如题。比如是第一行写有文本,当第一行写完了,richtextbox自动换行后(或者是人工敲回车键),这时候自动空出第二行,直接从第三行开始写?

解决方案 »

  1.   

    对,最好在richtextbox里。就是在richtextbox里写文本,需要换行的时候能够自动多加一个空行上去
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication8
    {
        public partial class Form1 : Form
        {
            RichTextBox RTB = new RichTextBox();        public Form1()
            {
                InitializeComponent();            RTB.Parent = this;
                RTB.TextChanged += new EventHandler(RTB_TextChanged);
            }        void RTB_TextChanged(object sender, EventArgs e)
            {
                if (RTB.Lines.Length > 0)
                {
                    if (RTB.Lines[RTB.Lines.Length - 1].Length > Math.Truncate(RTB.ClientSize.Width / RTB.Font.Size))
                    {
                        RTB.Text = RTB.Text + Environment.NewLine;
                        RTB.SelectionStart = RTB.TextLength;
                    }
                    if (RTB.Lines[RTB.Lines.Length - 1].Trim() == String.Empty)
                    {
                        RTB.Text = RTB.Text + Environment.NewLine;
                        RTB.SelectionStart = RTB.TextLength;
                    }
                }
            }
        }
    }