Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
C#
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;

    }
}
Posted
Updated 5-May-13 0:58am
v2
Comments
Maciej Los 5-May-13 7:25am    
What kind of library do you use: WinForms, WebControls?
Please, read about click event (WinForm)[^] and Button.Click Event (WebControls)[^].

1 solution

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:
C#
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
  this.Details.Visibility = Visibility.Hidden;
  this.Orders.Visibility = Visibility.Hidden;
}
 
Share this answer
 
Comments
Zain ul abdeen 6-May-13 11:48am    
Forms are designed in xaml not showing Form name.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900