当控件不可见时,MouseHover和MouseLeave不起作用 [英] MouseHover and MouseLeave don't work when the control is invisible
本文介绍了当控件不可见时,MouseHover和MouseLeave不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于某些原因,MouseHover和MouseLeave函数的行为确实很奇怪。我需要做的就是,当光标在按钮上时,我想使按钮可见,而当光标离开按钮时,我要使其不可见。无论我尝试什么,都无法正常工作。
For some reason MouseHover and MouseLeave functions behave really strange. All I need to do is, when the cursor is over the "button", I want to make the button visible and when the cursor leaves the button, I want to make it invisible. Whatever I try I couldn't make it work. It seems like Mouse events not working when the control object is invisible.
private void button1_MouseHover(object sender, EventArgs e)
{
button1.Visible = true;
}
private void button1_MouseLeave(object sender, EventArgs e)
{
button1.Visible = false;
}
推荐答案
嗯...就是这样有用。继续处理按钮的 MouseLeave
事件,并为其父项处理 MouseMove
(我以表格形式):
Well... that's how it works. Continue handling the button's MouseLeave
event and handle MouseMove
for its parent (I assume the form):
private void Form_MouseMove(object sender, MouseEventArgs e) {
if (button1.Bounds.Contains(e.Location) && !button1.Visible) {
button1.Show();
}
}
这篇关于当控件不可见时,MouseHover和MouseLeave不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文