滚动条上未检测到C#FlowLayoutPanel MouseMove事件

时间:2011-03-02 11:57:30

标签: c# .net winforms scrollbar

我有一个FlowLayoutPanel,AutoScroll = true 当滚动条可见时,我需要检测滚动条上鼠标的移动。

FlowLayoutPanel的MouseMove事件不会捕获与滚动条有关的事件。

有没有办法挂钩滚动条的鼠标移动?

2 个答案:

答案 0 :(得分:1)

class MyFlowLayoutPanel : FlowLayoutPanel
{
    const int WM_NCMOUSEMOVE = 0x00A0;

    protected override void WndProc(ref Message m)
    {
        if( m.Msg == WM_NCMOUSEMOVE )
        {
            Console.WriteLine("MouseOverScrollbar");
        }

        base.WndProc(ref m);
    }
}

答案 1 :(得分:0)

我试过这个(在LINQPAD中),看起来当鼠标在滚动条上时,MouseMoveEvent没有被提升。

void Main()
{
    Application.Run(new Form2());
}

public class Form2:Form
{
public Form2()
    {
        Label lbl= new Label();
        lbl.Location = new Point(200,40);
        this.Controls.Add(lbl);
        FlowLayoutPanel fl = new FlowLayoutPanel();fl.AutoScroll =true;
        fl.MouseMove += (s,e) => { lbl.Text = e.Location.Y.ToString();};
        this.MouseMove += (s,e) => { lbl.Text = e.Location.Y.ToString();};
        for(int i=0;i<10;i++){fl.Controls.Add(new Button());}
        this.Controls.Add(fl);

    }
}

enter image description here

这些ScrollBar.MouseMove事件,但我们无法直接使用。

等一下,看看是否有任何惊心动魄