Microsoft KB Archive/254703
Article ID: 254703
Article Last Modified on 5/13/2003
- Microsoft Visual Basic 6.0 Learning Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
This article was previously published under Q254703
When an MDI child form with a control is maximized, and another child form is created while the top child window is closed, the control on the original child form loses focus.
When the new child form is closed, the original form gets the focus instead of the control. The GotFocus event of the original form fires.
- Start a new Standard EXE project in Visual Basic. Form1 is created by default.
- Set the MDIChild property of Form1 to True.
- Add a TextBox to Form1.
- From the Project menu, add an MDI form to the project.
- From the Tools menu, select Menu Editor and create a menu item on the MDI form with the caption New Form and name it mnuNew.
Add the following code to the MDI form:
Private Sub mnuNew_Click() Dim tmpView As Form1 Set tmpView = New Form1 tmpView.Caption = "New Form" tmpView.Show End Sub
Add the following code to the General Declarations area of Form1:
Dim ctlFocus As Object Private Sub Form_Deactivate() Set ctlFocus = Me.ActiveControl End Sub Private Sub Form_GotFocus() ' Comment out the next two lines to reproduce behavior MsgBox "form got focus" ctlFocus.SetFocus End Sub
- Run the project and maximize Form1. The TextBox, Text1, has focus.
- Click on the MDI menu New Form. A new form is created. Close the new form.
- A message box indicates that the original form received the focus. Click OK. Focus is now set to the ActiveControl of the original form.
- Comment out the specified lines and repeat the steps above to see the problem reproduced.
Keywords: kbmdi kbprb KB254703