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

发布于 2024-10-19 18:57:44 字数 153 浏览 9 评论 0原文

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

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

有什么办法可以钩住滚动条的鼠标移动吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉殇 2024-10-26 18:57:44
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);
    }
}
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);
    }
}
挽你眉间 2024-10-26 18:57:44

我尝试了这个(在 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);

    }
}

在此处输入图像描述

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

等我看看是否有任何解决方法

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

    }
}

enter image description here

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

Wait while i see if there is any wokaround

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文