从自动滚动prevent的RichTextBox [英] Prevent RichTextBox from auto scrolling

查看:131
本文介绍了从自动滚动prevent的RichTextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想文本追加到一个的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?

推荐答案

确定这里正是你所需要的:<一href="http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/068b31bd-c659-4b21-a02a-46bf9b9f39f2/"相对=nofollow> 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.

这篇关于从自动滚动prevent的RichTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆