Microsoft KB Archive/201502

= PRB: Duplicate Control Boxes in MDIForm When Using Status Bar =

Article ID: 201502

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q201502



SYMPTOMS
When you are working with a Visual Basic project that contains a MDIform, and there are status bars on both the MDIForm and its child form, in order to display only one status bar when the active child form is maximized, the visible property of the status bar on the MDIForm is set to False. When a child form is open and maximized and another child form is opened, two sets of control boxes display.



CAUSE
This problem is caused by the incorrect calculation of the frame size. When the active child form is maximized, the MDIForm's status bar is not visible. However, when another form is opened and displayed, the status bar on the MDIForm is displayed and then hidden again, which causes the incorrect calculation of the frame size.



RESOLUTION
Prevent the Visible property of the status bar on the MDIForm from being changed to be True when at least one child form is maximized.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create a Visual Basic Standard EXE project. Form1 is created by default. From the Project menu, choose Add MDI Formand then click the Open button to add a multiple document interface (MDI) Form to the project. From the Project menu, choose Components, and select "Microsoft Windows Common controls X.X" from the components list and then click OK. Change Form1's MDIChild property to True. Add a StatusBar control to both Form1 and to MDIForm1.</li> Double click "MDIForm1" from the project window to make it the current form.</li> From the Tools menu, choose Menu Editor. Create a menu item specifying "Open" in the Caption text box and "mnuOpen" in the Name text box. Click OK.</li> From the Project menu, choose Project1 Properties and change the Startup Object to MDIForm1.</li>  Add the following code to the General Declarations section of MDIForm1: Option Explicit

Private Sub mnuOpen_Click Dim frm As Form Set frm = New Form1 frm.Display Me     End Sub

Public Property Let ShowStatusbar(bShowStatusbar As Boolean) On Error Resume Next If bShowStatusbar = True Then Me.StatusBar1.Visible = True Else Me.StatusBar1.Visible = False End If     End Property </li>  Add the following code to the General Declarations section of Form1: Option Explicit

Private m_ParentForm As MDIForm

Public Sub Display(ParentForm As MDIForm) Set m_ParentForm = ParentForm Me.Show End Sub

Private Sub Form_Resize If m_ParentForm Is Nothing Then Exit Sub End If        If Me.WindowState = 2 Then m_ParentForm.ShowStatusbar = False Else m_ParentForm.ShowStatusbar = True End If     End Sub </li> Run the application. Click the "Open" menu item. Maximize the child form. Click the "Open" menu item again and you will notice the duplicated control boxes at the upper right side.</li></ol>

Steps to Work Around the Behavior
<ol>  Replace the code in the General Declarations section of MDIForm1 with the following: Option Explicit

Private Sub mnuOpen_Click Dim frm As Form Set frm = New Form1 frm.Display Me     End Sub

Public Property Let ShowStatusbar(bShowStatusbar As Boolean) On Error Resume Next Dim i As Integer Dim bOneMaximized As Boolean

If bShowStatusbar = True Then If Forms.Count > 0 Then For i = 0 To Forms.Count - 1 If Forms(i).WindowState = 2 Then bOneMaximized = True Exit For End If              Next i            End If         End If

' Only set it to be true when there is no maximized child form. If bShowStatusbar = True And bOneMaximized = False Then Me.StatusBar1.Visible = True Else Me.StatusBar1.Visible = False End If     End Property </li> Run the application and repeat step 11. The application will now behave properly.</li></ol>

Additional query words: kbDSupport

Keywords: kbstatbar kbmdi kbprb KB201502

-

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

© Microsoft Corporation. All rights reserved.