问题
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?
回答1:
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.
Look for CoolColin answer:
The trick is to use the Windows
EM_HIDESELECTIONcall (this is different to the #hideselection), and also to temporarily remove the focus.
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.
Have a look at RichTextBox Class. At the end you need to use TextBoxBase.ScrollToCaret method.
来源:https://stackoverflow.com/questions/6695607/prevent-richtextbox-from-auto-scrolling