【问题标题】:Rectangle area over panel to catch mouse inputs面板上的矩形区域以捕获鼠标输入
【发布时间】:2015-07-21 01:09:44
【问题描述】:

c# winforms 在这里。我需要在面板上绘制一个不可见的矩形区域并捕捉他的鼠标进入/离开事件。

我的情况(至于您可能有的其他建议):

我有一个媒体播放器(面板),在鼠标输入事件中,我可以看到一个小导航菜单(它位于面板上方)。我想从面板中隐藏鼠标离开时的导航菜单。这可行,但不幸的是,进入导航菜单也使其不可见。非常感谢。

【问题讨论】:

    标签: c# draw mouseenter mouseleave


    【解决方案1】:

    鼠标离开时,只需查看当前的Cursor.Position 是否包含在您的矩形中。例如,使用面板和标签:

        public Form1()
        {
            InitializeComponent();
            panel1.MouseEnter += panel1_MouseEnter;
            panel1.MouseLeave += common_MouseLeave;
            label1.MouseLeave += common_MouseLeave;
        }
    
        private void panel1_MouseEnter(object sender, EventArgs e)
        {
            label1.Visible = true;
        }
    
        private void common_MouseLeave(object sender, EventArgs e)
        {
            Rectangle rc = panel1.RectangleToScreen(panel1.ClientRectangle);
            if (!rc.Contains(Cursor.Position))
            {
                label1.Visible = false;
            }
        }
    

    【讨论】:

    • 绝对完美。它就像一个魅力!非常感谢!
    猜你喜欢
    • 2011-05-24
    • 2012-08-16
    • 1970-01-01
    • 2021-06-25
    • 2012-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    相关资源
    最近更新 更多