Microsoft KB Archive/254703

= PRB: Maximized MDI Child Form with Control Loses Focus =

Article ID: 254703

Article Last Modified on 5/13/2003

-

APPLIES TO


 * 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



SYMPTOMS
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.



CAUSE
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.



Step-by-Step Workaround
 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 </li>  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 </li> Run the project and maximize Form1. The TextBox, Text1, has focus.</li> Click on the MDI menu New Form. A new form is created. Close the new form.</li> A message box indicates that the original form received the focus. Click OK. Focus is now set to the ActiveControl of the original form.</li> Comment out the specified lines and repeat the steps above to see the problem reproduced.</li></ol>

Keywords: kbmdi kbprb KB254703

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.