[英]Position TextBox Caret/Cursor to Same Line as Other Textbox C#
我一直在寻找,但是我尝试过的任何方法都没有用。
我基本上想从一个文本框中选择插入符号所在的行,然后将第二个文本框滚动到相同位置。
这是我尝试的:
int line = textBox1.GetLineFromCharIndex(textBox1.SelectionStart);
Point pNew = new Point();
pNew.X = 0;
pNew.Y = line;
textBox2.SelectionStart = textBox2.GetCharIndexFromPosition(pNew);
textBox2.ScrollToCaret();
我要做的就是保持第二个文本框的滚动与第一个文本框的滚动相同。
这是你想要的吗 :
textBox2.SelectionStart = textBox1.SelectionStart;
textBox2.ScrollToCaret();
这在两个文本框文本相等的地方有效。
我没有得到您All I want to do is keep the second textbox as scrolled as much as the first textbox.
的All I want to do is keep the second textbox as scrolled as much as the first textbox.
目的, All I want to do is keep the second textbox as scrolled as much as the first textbox.
我认为:两个TextBox具有相同的Text。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.