Form's lost focus in C#
22,154
Solution 1
Use the Deactivate
event handler
Solution 2
If I understand your question, I think you actually want to trap deactivation. Button handler inside your main form:
private void button1_Click(object sender, EventArgs e)
{
Form childForm = new Form();
childForm.Deactivate += delegate
{
childForm.Close();
};
childForm.Show();
}
Author by
Admin
Updated on May 18, 2020Comments
-
Admin almost 4 years
This may be a simple C# question but I need a solution.
I have two forms, form1 and form2, with form1 having a button. On the click of the button, I want to show form2. When form2 looses focus I want to hide it (form2). How can I do this? I tried to subscribe to the LostFocus event of form2, but it isn't working.
Please help me with this.
Note -- I use .Net 2.0
-
Diuter about 15 yearsFrom her description, she probably wants .Hide(), not .Close(), but +1 anyway