Consider the following scenario. In a Microsoft Windows Forms-based application, a top-level form owns a pop-up window, and the pop-up window raises a modal dialog box. In this scenario, the wrong application may come to the foreground when you close the modal dialog box. The top-level form that owns the pop-up window may not come to the foreground as expected.
This problem occurs when the pop-up window closes itself explicitly or when the pop-up window creates a modal dialog box in the pop-up form's
Closing event. This problem occurs on a computer that has the Microsoft .NET Framework 2.0 or the Microsoft .NET Framework 1.1 installed.
Back to the top
This problem may occur if the pop-up window closes immediately after the user closes the modal dialog box.
Back to the top
To work around this problem, use one of the following methods:
| • | Set the top-level form as the owner of the modal dialog box. To do this, you can use code that is similar to the following.MessageBox.Show(Me.Owner, "ok") |
| • | Set the Owner property of the pop-up window to Nothing before you display the modal dialog box. To do this, you can use code that is similar to the following.Private Sub Button1_Click(...)
Dim f As Form
f = Me.Owner
Me.Owner = Nothing
MessageBox.Show("ok")
Me.Owner = f
Me.Close()
End SubNote When you set the Owner property of the pop-up window to Nothing, the focus is correctly reset to the active window or to the pop-up window. |
Back to the top
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
Back to the top