views:

2770

answers:

2

This may be a simple C# question but I need a solution thou'

I have two forms, form1 and form2, with form1 having a button. On the click of the button, I wanna show form2. But when this form2 looses foucs I wanna hide it (form2). How do I do it ?? I tried to subscribe to LostFocus event of form2, but it isn't working.

Please help me with this.

Note -- I use .Net 2.0

+2  A: 

Use the "Deactivate" event handler

Jcl
Oops. I missed that event
+1  A: 

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

HTH, Kent

Kent Boogaart
From her description, she probably wants .Hide(), not .Close(), but +1 anyway
Matt Jordan