Microsoft KB Archive/871045

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

Article ID: 871045

Article Last Modified on 5/18/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * 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 &quot;More Information&quot; 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:  In Solution Explorer, right-click the Form2.vb file, and then click View Code.  Locate the following code in the Form2 class: Public Class Form2 Inherits System.Windows.Forms.Form   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.  </ul>

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:  In Solution Explorer, right-click the Form2.vb file, and then click View Code.</li>  Locate the following code in the Form2 class: Public Class Form2 Inherits System.Windows.Forms.Form </li>  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. </li>  Change the code in step 14 of the &quot;More Information&quot; section to the following: Dim frm As Form2 frm = New Form2(Me, FormWindowState.Maximized) frm.Show </li></ol>

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 &quot;Symptoms&quot; section mentions.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.

<div class="moreinformation_section">

Steps to reproduce the behavior
 Start Visual Studio .NET 2003.</li> On the File menu, point to New, and then click Project. The New Project dialog box appears.</li> Under Project Types, click Visual Basic Projects, and then click Windows Application under Templates.</li> In the Name box, type MyMDIProject, and then click OK. By default, a form that is named Form1 is created.</li> On the Project menu, click Add Windows Form, and then click Open. By default, a form that is named Form2 is created.</li> On the View menu, click Toolbox.</li> Right-click the toolbox, and then click Add/Remove Items. The Customize Toolbox dialog box appears.</li> In the Customize Toolbox dialog box, click the COM Components tab.</li> 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.</li> 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.</li> <li>In the Properties dialog box of the Form1, set the IsMdiContainer property to true.</li> <li>Add a MainMenu control to the Form1.</li> <li>Click MainMenu control and set the Text property of MenuItem1 to New .</li> <li> 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 </li> <li>On the File menu, click Save All to save all the files.</li> <li>On the Build menu, click Build Solution.</li> <li>On the Debug menu, click Start.</li> <li>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.</li></ol>

<div class="references_section">