【问题标题】:How to synchronize scrolling of a textbox and listbox如何同步滚动文本框和列表框
【发布时间】:2015-03-27 16:38:04
【问题描述】:

我想设计一个文本框,它的每一行的索引在一个单独的列表框旁边。一切都差不多完成了,但滚动对我来说仍然是一个问题。当我使用WndProc 来控制滚动时,WM_VSCROLL效果很好,同时使两个控件滚动,但是当我想通过列表框发送WM_MOUSEWHEEL 时,它不起作用。我想我可以使用一个技巧并在用户移动鼠标滚轮时迭代WM_VSCROLL 但是它也不起作用。

    private const int WM_VSCROLL = 0x115;
    private const int WM_MOUSEWHEEL = 0x20A;
    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);            
        if (m.Msg == WM_VSCROLL )
        {
            Message newMessage = Message.Create(Sequence.Handle, m.Msg, m.WParam, m.LParam);
            Sequence.DirectMessage(newMessage);//turn to thread
        }
        else if(m.Msg == WM_MOUSEWHEEL)
        {
            if((int)m.WParam<0)
            {

                Message newMessage = Message.Create(Sequence.Handle, WM_VSCROLL,(IntPtr)1,(IntPtr) 0);
                Message newMessage2 = Message.Create(this.Handle, WM_VSCROLL, (IntPtr)1, (IntPtr)0);                    
                Sequence.DirectMessage(newMessage);
                base.WndProc(ref newMessage2);
            }
            else
            {
                Message newMessage = Message.Create(Sequence.Handle, WM_VSCROLL, (IntPtr)0, (IntPtr)0);
                Message newMessage2 = Message.Create(this.Handle, WM_VSCROLL, (IntPtr)0, (IntPtr)0);
                Sequence.DirectMessage(newMessage);
                base.WndProc(ref newMessage2);
            }
        }
    }

Sequence 是我的列表框的名称,this 推断我的文本框。我将不胜感激任何形式的帮助...。

【问题讨论】:

    标签: c# .net winforms listbox scroll


    【解决方案1】:

    WM_SCROLL

    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    internal static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
    
    private const int WM_VSCROLL = 0x115;
    private const int WM_MOUSEWHEEL = 0x20A;
    
    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_VSCROLL || m.Msg == WM_MOUSEWHEEL)
        {
            SendMessage(Sequence.Handle, (UInt32)m.Msg, m.WParam, m.LParam);
        }
    
        base.WndProc(ref m);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 2011-04-18
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多