我的表单在 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;
}
..期望组面板,因为它们没有 MouseMove
和 MouseLeave
事件。可以添加吗?标准面板也有它们。
我真的很喜欢那个 GroupPanel 的布局(带有那个边框和文本),这就是为什么我希望能够用 GroupBox 解决这个问题。
我创建的小工具只有在光标位于表单内或表单外时才会被触发。 (不管是不活动还是事件)。也许还有另一种触发它的方法,而不是 MouseMove
和 MouseLeave
。
最佳答案
使用计时器可能是最简单的解决方案!
谢谢LarsTech用于链接到此 'Winform - determine if mouse has left user control'问题。
我可以使用下面的示例继续我的项目。
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
关于c# - GUI GroupPanel 鼠标事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16856919/