从自动滚动prevent的RichTextBoxprevent、RichTextBox

由网友(再见陌路)分享简介:我想文本追加到一个的RichTextBox 控制,但我不想干扰用户的滚动位置或文本选择。我已经能够做到这一点迄今为止最好的是保存 SelectionStart 和 SelectionLength 属性和后恢复它们我附上我的文字。这是接近但光标结束于该控制而不是无论它是之前追加的顶部。这可能吗?I want to ap...

我想文本追加到一个的RichTextBox 控制,但我不想干扰用户的滚动位置或文本选择。我已经能够做到这一点迄今为止最好的是保存 SelectionStart SelectionLength 属性和后恢复它们我附上我的文字。这是接近但光标结束于该控制而不是无论它是之前追加的顶部。这可能吗?

I want to append text to a RichTextBox control but I don't want to interfere with the user's scroll position or text selection. The best that I've been able to do so far is to save the SelectionStart and SelectionLength properties and restore them after I append my text. This is close but the cursor ends up at the top of the control rather than wherever it was prior to the append. Is this possible?

推荐答案

确定这里正是你所需要的: RichTextBox的: - 文本追加时控制滚动

Ok here is exactly what you need: Richtextbox :- controlling scrolling when appending text.

在那里,你会发现如何追加文本时锁定卷轴。

There you will find how to lock the scroll when appending text.

查找CoolColin回答:

Look for CoolColin answer:

的技巧是使用Windows EM_HIDESELECTION 电话(这是不同于# hideselection ),并且还暂时删除的焦点。

The trick is to use the Windows EM_HIDESELECTION call (this is different to the # hideselection), and also to temporarily remove the focus.

您可以使用的RichTextBox 控件获取的 SelectionStart 属性或设置文本的起点选择在文本框中输入。的价值观,你已经存储。

You can use the SelectionStart property of your RichTextBox control to "Gets or sets the starting point of text selected in the text box." with the values you already stored.

看一看 RichTextBox类 。在最后,你需要使用 TextBoxBase.ScrollToCaret 的方法。

Have a look at RichTextBox Class. At the end you need to use TextBoxBase.ScrollToCaret method.

阅读全文

相关推荐

最新文章