The wrong application may come to the foreground when you close a modal dialog box in a Windows Forms-based application on the .NET Framework 2.0 or on the .NET Framework 1.1 (905719)
The information in this article applies to:
- Microsoft .NET Framework 2.0
- Microsoft .NET Framework 1.1
SYMPTOMSConsider 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.CAUSEThis problem may occur if the pop-up window closes immediately after the user closes the modal dialog box.WORKAROUNDTo 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 Sub Note 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.
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
Modification Type: | Major | Last Reviewed: | 11/3/2005 |
---|
Keywords: | kbDev kbtshoot kbcode kbprb KB905719 kbAudDeveloper |
---|
|