点击其他东西时隐藏按钮 [英] Hide Buttons when click on other thing

查看:89
本文介绍了点击其他东西时隐藏按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有论坛,我有按钮。当鼠标点击FarmerButton时,它会再显示2个按钮,再次单击时会隐藏这些按钮。现在我想在用户点击时隐藏这些按钮(现在正在工作),当用户选择或点击论坛上的任何其他地方我的代码在下面

Hi Ihave forum in which I have buttons. When mouse clicks on FarmerButton it shows 2 more buttons and when click again it hides those buttons. Now I want to hide those buttons when user clicks (Its working now) and when user select or click anywhere else on forum My code is below

this.Farmer.MouseLeftButtonDown += new MouseButtonEventHandler(Farmer_MouseLeftButtonDown);
    this.Farmer.LostFocus += new RoutedEventHandler(Farmer_LostFocus);
}

void Farmer_LostFocus(object sender, RoutedEventArgs e)
{
    this.Details.Visibility = Visibility.Hidden;
    this.Orders.Visibility = Visibility.Hidden;

}

void Farmer_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    if (this.Details.Visibility != Visibility.Visible || this.Orders.Visibility != Visibility.Visible)
    {
        this.Details.Visibility = Visibility.Visible;
        this.Orders.Visibility = Visibility.Visible;
    }

    else
    {
        this.Details.Visibility = Visibility.Hidden;
        this.Orders.Visibility = Visibility.Hidden;

    }
}

推荐答案

隐藏按钮的代码放在LostFocus事件中Farmer按钮的处理程序。这只有在Focus目前在Farmer按钮上并且你点击其他地方时才有效。



尝试将代码放在Form的MouseClick事件中。

可能看起来像这样:

your code to hide the buttons are placed in the LostFocus event handler of the Farmer button. This will only work if the Focus is currently on the Farmer button and you click elsewhere.

Try placing the code in the MouseClick event of the Form.
Probably would look something like this:
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
  this.Details.Visibility = Visibility.Hidden;
  this.Orders.Visibility = Visibility.Hidden;
}


这篇关于点击其他东西时隐藏按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆