C#获取richtextbox滚动条当前位置
C#获取richtextbox滚动条当前位置scrolltop属性值,可以通过导入user32.dll动态库,然后使用GetScrollPos得到。
+展开
-C#
public class MyRichTextBox: RichTextBox
{
[DllImport( "user32 ")]
private static extern int GetScrollPos(IntPtr hWnd, Int32 nBar);
private const Int32 WM_VSCROLL = 0x00000115;
private const Int32 SB_VERT = 0x00000001;
public delegate void ScrollEventHandler(object sender, Int32 position);
public event ScrollEventHandler VScroll;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_VSCROLL)
{
int position = GetScrollPos(m.HWnd, SB_VERT);
VScroll(this, position);
}
base.WndProc(ref m);
}
}
{
[DllImport( "user32 ")]
private static extern int GetScrollPos(IntPtr hWnd, Int32 nBar);
private const Int32 WM_VSCROLL = 0x00000115;
private const Int32 SB_VERT = 0x00000001;
public delegate void ScrollEventHandler(object sender, Int32 position);
public event ScrollEventHandler VScroll;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_VSCROLL)
{
int position = GetScrollPos(m.HWnd, SB_VERT);
VScroll(this, position);
}
base.WndProc(ref m);
}
}
加支付宝好友偷能量挖...