日期:2014-05-17  浏览次数:20976 次

请教Winform程序RichTextBox控件只显示前1000行,如何做到,谢谢
请教各位前辈:
Winform程序RichTextBox控件只显示前1000行应该如何写代码,谢谢!

------解决方案--------------------

 private void btnTest_Click(object sender, EventArgs e)
        {
            // 这里控制显示行数
            richTextBox1.Lines = richTextBox1.Lines.Take(20).ToArray();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string[] arr = new string[100];
            for (int i = 0; i < 100; i++)
            {
                arr[i] = i.ToString();
            }
            richTextBox1.Lines = arr;
        }

------解决方案--------------------
 private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            List<string> TempLi = new List<string>();
            if (richTextBox1.Lines.Length > 10)
            {
                TempLi.AddRange(richTextBox1.Lines);
                richTextBox1.Lines = TempLi.GetRange(richTextBox1.Lines.Length - 10, 10).ToArray();
                richTextBox1.Select(richTextBox1.Text.Length - 1, 0);
            }
        }



把10改成1000就OK了