BUG: An MDI child form may not maximize if the child form contains an ActiveX control in Visual Studio .NET 2003 (871045)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition

SYMPTOMS

When you use an ActiveX control in a Multiple-Document Interface (MDI) child form in Microsoft Visual Studio .NET 2003, you may experience the following problems:
  • The MDI child form may not maximize.
  • You cannot change focus to another inactive MDI child form if you click the client area of the inactive MDI child form.

CAUSE

This problem occurs because your application may not treat forms as correct MDI child forms when the following conditions are true:
  • You work with Microsoft Windows forms in MDI mode in Visual Studio .NET 2003.
  • You use an ActiveX control in an MDI child form.

WORKAROUND

To work around this problem, use one of the following methods:

Method 1

Modify the code so that you can maximize the child form, and then modify the code so that you can obtain the focus of an inactive child form:
  • To maximize a child form, change the code in step 14 of the "More Information" section to the following:
    Dim frm As Form2
    frm = New Form2
    frm.MdiParent = Me
    frm.WindowState = FormWindowState.Maximized
    frm.Show()
    Note The MdiParent property is used to specify that the Form2 form is a child form.
  • To obtain the focus of an inactive child form by clicking the client area of the child form, add code to the child form:
    1. In Solution Explorer, right-click the Form2.vb file, and then click View Code.
    2. Locate the following code in the Form2 class:
      Public Class Form2
          Inherits System.Windows.Forms.Form
    3. Add the following code after the code that you located in step 2:
      Private Const WM_MOUSEACTIVATE As Integer = &H21
      
          Protected Overrides Sub WndProc(ByRef m As Message)
              If m.Msg = WM_MOUSEACTIVATE Then
                  Me.Focus()
              End If
              MyBase.WndProc(m)
      End Sub
      The WM_MOUSEACTIVATE message is sent when the pointer is in an inactive window and the user clicks a mouse button. The WndProc method activates the current MDI child form if the WndProc method receives the WM_MOUSEACTIVATE message.

Method 2

Set the MdiParent property and the WindowState property of the child form before you call the InitializeComponent method in the child form. To do this, you must write code that creates a constructor that takes the MdiParent property and the WindowState property as arguments and that creates a form as an MDI child form:
  1. In Solution Explorer, right-click the Form2.vb file, and then click View Code.
  2. Locate the following code in the Form2 class:
    Public Class Form2
        Inherits System.Windows.Forms.Form
  3. Add the following code after the code that you located in step 2:
    Public Sub New(ByVal mdiParent As Form, ByVal initialState As FormWindowState)
            MyBase.New()
    
            Me.MdiParent = mdiParent
            Me.WindowState = initialState
    
            InitializeComponent()
    
    End Sub
    The constructor initializes the MdiParent property of the child form to specify the parent form. The constructor also initializes the WindowState property of the child form before the constructor calls the InitializeComponent method.
  4. Change the code in step 14 of the "More Information" section to the following:
    Dim frm As Form2
    frm = New Form2(Me, FormWindowState.Maximized)
    frm.Show()
You must change the code in all the MDI child forms that contain an ActiveX control if you want to work around the problems that the "Symptoms" section mentions.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the behavior

  1. Start Visual Studio .NET 2003.
  2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
  3. Under Project Types, click Visual Basic Projects, and then click Windows Application under Templates.
  4. In the Name box, type MyMDIProject, and then click OK. By default, a form that is named Form1 is created.
  5. On the Project menu, click Add Windows Form, and then click Open. By default, a form that is named Form2 is created.
  6. On the View menu, click Toolbox.
  7. Right-click the toolbox, and then click Add/Remove Items. The Customize Toolbox dialog box appears.
  8. In the Customize Toolbox dialog box, click the COM Components tab.
  9. On the COM Components tab, double-click Microsoft Date and Time Picker Control 6.0 (SP6), and then click OK. The Microsoft Date and Time Picker Control 6.0 (SP6) appears under My User Controls in the toolbox.
  10. Double-click Microsoft Date and Time Picker Control 6.0 (SP6) to add the Microsoft Date and Time Picker Control 6.0 (SP6) control to the Form2.
  11. In the Properties dialog box of the Form1, set the IsMdiContainer property to true.
  12. Add a MainMenu control to the Form1.
  13. Click MainMenu control and set the Text property of MenuItem1 to New.
  14. On the Form1 form, double-click New, and then add the following code to the MenuItem1_Click event handler in the Form1 form:
    Dim frm As Form2
    frm = New Form2
    frm.WindowState = FormWindowState.Maximized
    frm.MdiParent = Me
    frm.Show()
  15. On the File menu, click Save All to save all the files.
  16. On the Build menu, click Build Solution.
  17. On the Debug menu, click Start.
  18. Click New on the menu bar of the Form1. A Form2 child window appears.

    The Form2 window is not maximized. However, you can maximize it manually. If you have multiple MDI child forms, you cannot change focus to another child form by clicking the client area of the child form. However, you can change the focus if you click the title bar of the inactive child form.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web sites:

Modification Type:MinorLast Reviewed:2/3/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbForms kbBug kbtshoot KB871045 kbAudDeveloper