本文介绍了C#的WinForms MouseHover和鼠标离开的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因MouseHover和鼠标离开函数的行为真的很奇怪。所有我需要做的是,当光标在按钮,我想使按钮可见,当光标离开按钮,我想使它不可见。无论我尝试我不能使它工作。这似乎是在控制对象是无形的不工作的鼠标事件。

 私人无效button1_MouseHover(对象发件人,EventArgs的发送)
{
   button1.Visible = TRUE;
}私人无效button1_MouseLeave(对象发件人,EventArgs的发送)
{
    button1.Visible = FALSE;
}


解决方案

好吧......这是它如何工作的。继续处理按钮的鼠标离开事件和处理的MouseMove 其父(我假设的形式):

 私人无效Form_MouseMove(对象发件人,MouseEventArgs E){
    如果(button1.Bounds.Contains(e.Location)及&放大器;!button1.Visible){
        button1.Show();
    }
}

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;
}
解决方案

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

这篇关于C#的WinForms MouseHover和鼠标离开的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 05:09