简体   繁体   中英

C# FlowLayoutPanel MouseMove event not detected on scrollbar

I have a FlowLayoutPanel with AutoScroll = true I need to detect the movement of the mouse on the scrollbar when the scrollbar is visible.

The MouseMove event of the FlowLayoutPanel does not capture events pertaining to the scrollbar.

Is there any way to hook on to the mouse move of the scrollbar?

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

I tried this(in LINQPAD) and looks like when mouse is on scrollbar MouseMoveEvent is not raised.

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

    }
}

在此处输入图片说明

These's ScrollBar.MouseMove event but its not available for direct use by us.

Wait while i see if there is any wokaround

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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