How to move scroll bar up by one line? (In C# RichTextBox)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 17:36:28

Here's what I do:

using System.Runtime.InteropServices;

[DllImport("user32.dll")]
static extern int SendMessage(IntPtr hWnd, uint wMsg, 
                               UIntPtr wParam, IntPtr lParam);

then call:

SendMessage(myRichTextBox.Handle, (uint)0x00B6, (UIntPtr)0, (IntPtr)(-1));

Seems to work OK - you might need to tweak things a bit, though.

Hope that helps.

For future reference the EM_LINESCROLL message is what you send to any multi-line edit control to set the scroll position. You can scroll vertically or horizontally. See MSDN for details.

You can also use the Rich Edit Selection method, where you set the character index (which you can get with EM_LINEINDEX) then call RichEdit.ScrollToCaret ie:

RichEdit.SelectionStart = SendMessage(RichEdit.Handle, EM_LINEINDEX, ScrollTo, 0);
RichEdit.ScrollToCaret();

This will scroll that line to the top of the edit control.

window.scrollBy(0,20);

This will scroll the window. 20 is an approximate value I have used in the past that typically equals one line... but of course font size may impact how far one line really is.

If you can get the scroll control for the rich text box, you should be able to get its SmallChange property and use that to scroll the text.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!