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

查看:76
本文介绍了C#:SetScrollPos(user32.dll)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有2个(丰富的)texbox(vc#2k8)具有相同的滚动...因此,当我滚动tb1时,tb2滚动到相同位置.我使用以下功能:

I want to have 2 (rich)texboxes (vc# 2k8) with same scrolling... so when I scroll tb1 the tb2 scrolls to the same position. 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);

那很好,但是

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

仅将滚动条设置为相同位置,但向下更新其中的文本.tb2.Update()或刷新无法正常工作...

only sets the scrollbar to the same position but down update the text in there. tb2.Update() oder Refresh won't work...

请帮助.Ty

推荐答案

我找到了答案

[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);
} 

这篇关于C#:SetScrollPos(user32.dll)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆