我正在使用Visual Studio 2010(C#)和Windows窗体应用程序.
我有两个并排的树视图,我已经想出如何使用滚动条上的向上/向下按钮同步滚动,但是当我使用滑块时,它不会移动其他树视图.我已经采用了一个有效的listview示例,但相同的代码不适用于树视图.
到目前为止,我的主要形式是:
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
private void myListBox1_Scroll(ref Message m)
{
SendMessage(myListBox2.Handle, (uint)m.Msg, (uint)m.WParam, (uint)m.LParam);
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个控件:
public partial class MyTreeView : TreeView
{
public MyTreeView()
{
InitializeComponent();
}
public event ScrollEventHandler Scroll;
public delegate void ScrollEventHandler(ref Message m);
private const int WM_VSCROLL = 0x115;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == WM_VSCROLL)
if (Scroll != null)
{
Scroll(ref m);
}
base.WndProc(ref m);
} …Run Code Online (Sandbox Code Playgroud)