T
Tom Clement
Hi everyone,
I need some help on a problem I'm seeing. Some very simple code causes the
current application to lose focus. It looks to me like a fundamental
WinForms bug, but perhaps I'm missing something. Here's the
easy-to-reproduce situation.
1. Bring up an application (Form1). Switch focus to another application
(Outlook for example), then back to Form1.
2. A winforms main form (Form1) calls a modeless dialog (Form2) using the
following code:
private void button1_Click(object sender, System.EventArgs e) // Form1.cs
{
Form2 frm = new Form2();
frm.Owner = this;
frm.Show();
}
3. Form2 calls a modal dialog using the following code: //
Form2.cs
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm = new Form3();
frm.ShowDialog();
}
4. Close Form3 using the close box (or by calling .Close()).
5. Hide Form2 using the following code:
// Form2.cs
private void button2_Click(object sender, System.EventArgs e)
{
this.Hide();
}
At this point, Outlook will have focus and Form1 will be hidden behind it.
You can see this at design time where VS.NET will get focus. Can someone
give me some help understanding what's going on here? Have I missed
something in the documentation (or these newsgroups) that would explain it?
Tom Clement
Apptero, Inc.
I need some help on a problem I'm seeing. Some very simple code causes the
current application to lose focus. It looks to me like a fundamental
WinForms bug, but perhaps I'm missing something. Here's the
easy-to-reproduce situation.
1. Bring up an application (Form1). Switch focus to another application
(Outlook for example), then back to Form1.
2. A winforms main form (Form1) calls a modeless dialog (Form2) using the
following code:
private void button1_Click(object sender, System.EventArgs e) // Form1.cs
{
Form2 frm = new Form2();
frm.Owner = this;
frm.Show();
}
3. Form2 calls a modal dialog using the following code: //
Form2.cs
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm = new Form3();
frm.ShowDialog();
}
4. Close Form3 using the close box (or by calling .Close()).
5. Hide Form2 using the following code:
// Form2.cs
private void button2_Click(object sender, System.EventArgs e)
{
this.Hide();
}
At this point, Outlook will have focus and Form1 will be hidden behind it.
You can see this at design time where VS.NET will get focus. Can someone
give me some help understanding what's going on here? Have I missed
something in the documentation (or these newsgroups) that would explain it?
Tom Clement
Apptero, Inc.