try using interop.
public const int SBS_HORZ = 0;
public const int SBS_VERT = 1;
public const int SBS_CTL = 2;
public const int SBS_BOTH = 3;
public const int WM_VSCROLL = 0x0115;
public const int WM_HSCROLL = 0x114;
public const int SB_LINEUP = 0;
public const int SB_LINEDOWN = 1;
public const int SB_PAGEUP = 2;
public const int SB_PAGEDOWN = 3;
public const int SB_THUMBPOSITION = 4;
public const int SB_THUMBTRACK = 5;
public const int SB_TOP = 6;
public const int SB_BOTTOM = 7;
public const int SB_ENDSCROLL = 8;
[DllImport("User32.dll",CharSet = CharSet.Auto,SetLastError=true)]
public static extern int GetScrollPos(IntPtr hWnd, int nBar);
[DllImport("User32.dll",CharSet = CharSet.Auto,SetLastError=true)]
public static extern bool PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
[DllImport("User32.dll",CharSet = CharSet.Auto,SetLastError=true)]
public static extern int GetScrollRange(IntPtr hwnd, int nBar, ref int lpMinPos, ref int lpMaxPos);
For example to get the vertical scrollbar position of a RichTextBox:
int pos = GetScrollPos(richTextBox1.Handle, SBS_VERT);
To Set the scrollbar position of a RichTextBox:
int position = 500;
PostMessage (richTextBox1.Handle,WM_VSCROLL ,SB_THUMBPOSITION + 0x10000 * position,0);
To find out the maximum scroll position of a RichTextBox:
int minValue=0, maxValue=0;
GetScrollRange(richTextBox1.Handle, SBS_VERT, ref minValue, ref maxValue);
maxValue -= richTextBox1.Height;
AlexS said:
I would like to get current position of scrollbars when they are present for
scrolled content and revert to it later. Without this sometimes Form scrolls
automatically to top when getting focus back.
Any pointers?
Thanks