2

我的表单与 GroupBbox MouseEvents 有问题。

我正在尝试制作一些 GUI 小工具(对接、不透明度..)。

这是一个例子:

皮克特

我已经将所有(GUI)对象链接到这两个函数。

private void MyMouseMove(object sender, MouseEventArgs e)
{
    this.Opacity = 1;
}

private void MyMouseLeave(object sender, EventArgs e)
{
    this.Opacity = 0.5;
}

..期待小组小组,因为他们没有MouseMoveMouseLeave事件。可以添加吗?标准面板也有它们。

我真的很喜欢 GroupPanel 的布局(带有边框和文本),这就是为什么我希望能够使用 GroupBox 解决这个问题。

只有当光标在表单内或表单外时,才会触发我创建的小工具。(不管是非活动还是活动)。也许还有另一种触发它的方法,而不是MouseMoveand MouseLeave

4

1 回答 1

0

使用计时器可能是最简单的解决方案!
感谢LarsTech链接到这个“Winform - 确定鼠标是否离开用户控制”问题。

我可以使用下面的示例继续我的项目。

public partial class Form1 : Form
{
    private Timer timer1;
    public Form1()
    {
        InitializeComponent();
        this.Opacity = 0.5D;
        timer1 = new Timer();
        timer1.Interval = 200;
        timer1.Tick += timer1_Tick;
        timer1.Enabled = true;
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        if (this.DesktopBounds.Contains(Cursor.Position))
            this.Opacity = 1D;
        else
            this.Opacity = 0.5D;
    }
}

致谢:Hans Passant

于 2013-06-01T11:58:10.820 回答