Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/254703

From BetaArchive Wiki
Knowledge Base


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.

RESOLUTION

Step-by-Step Workaround

  1. Start a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. Set the MDIChild property of Form1 to True.
  3. Add a TextBox to Form1.
  4. From the Project menu, add an MDI form to the project.
  5. 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.
  6. 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
                        
  7. 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
                        
  8. Run the project and maximize Form1. The TextBox, Text1, has focus.
  9. Click on the MDI menu New Form. A new form is created. Close the new form.
  10. A message box indicates that the original form received the focus. Click OK. Focus is now set to the ActiveControl of the original form.
  11. Comment out the specified lines and repeat the steps above to see the problem reproduced.


Keywords: kbmdi kbprb KB254703