怎么能让richTextBox滚动条滚到最下?

来源:互联网 发布:微夏域名授权系统源码 编辑:程序博客网 时间:2024/06/10 15:16

方法一:

       private void GoToLineAndColumn(RichTextBox RTB, int Line, int Column)
        {

            int offset = 0;

            for (int i = 0; i < Line - 1 && i < RTB.Lines.Length; i++)
            {

                offset += RTB.Lines[i].Length + 1;

            }

            RTB.Focus();

            RTB.Select(offset + Column, 0);

        }
 

        private void button1_Click(object sender, EventArgs e)
        {
           GoToLineAndColumn(richTextBox1, richTextBox1.Lines.Length, 0);
        }

方法二:

// 让光标定位到文本框末尾
this.richTextBox1.Select(this.richTextBox1.TextLength, 0);

//然后移动滚动条,使输入点(text entry point)(即光标所在的位置)显示出来
//这样也可以达到滚动到最下方的目的
this.richTextBox1.ScrollToCaret();