简体   繁体   English

c#:SetScrollPos(user32.dll)

[英]c#: SetScrollPos (user32.dll)

I want to have 2 (rich)texboxes (vc# 2k8) with same scrolling... so when I scroll tb1 the tb2 scrolls to the same position. 我希望有2个(丰富的)texbox(vc#2k8)具有相同的滚动...所以当我滚动tb1时,tb2滚动到相同的位置。 I use this functions: 我用这个函数:

[DllImport("user32.dll")]
static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool bRedraw);

[DllImport("user32.dll")]
public static extern int GetScrollPos(IntPtr hwnd, int nBar);

That works fine but 这很好,但是

int pos = GetScrollPos(tb1.Handle, 1);
SetScrollPos(tb2.Handle, 1, pos, true);

only sets the scrollbar to the same position but down update the text in there. 仅将滚动条设置为相同位置,但向下更新其中的文本。 tb2.Update() oder Refresh won't work... tb2.Update()或刷新不起作用......

Please help. 请帮忙。 Ty

I found answer 我找到了答案

[DllImport("user32.dll")]
static extern int SetScrollPos(IntPtr hWnd, int nBar,
                int nPos, bool bRedraw);

[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);



public void ScrollTo(int Position) {
    SetScrollPos((IntPtr)textBox1.Handle, 0x1, Position, true);
    PostMessage((IntPtr)textBox1.Handle, 0x115, 4 + 0x10000 * Position, 0);
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM