Microsoft KB Archive/96097

= FIX: Resizing MDIForm with UI Does Not Update Height & Width =

Article ID: 96097

Article Last Modified on 10/30/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 2.0 Professional Edition

-



This article was previously published under Q96097



2.00 WINDOWS kbprg kbbuglist



SYMPTOMS
If a user resizes a MDIForm at run time with the mouse, the Height and Width properties for the MDIForm incorrectly retain their previous values. Resizing the form by using the user interface (the mouse or the system menus) should change the Height and Width properties to reflect the new size of the MDIForm. Changing the Height and Width properties in code does correctly update the properties.



WORKAROUND
This problem occurs only when a user uses the user interface to change the size of the MDIForm. Therefore, to work around the problem, you can use code to change the Width and Height properties.

The GetWindowRect Windows API function retrieves the dimensions of the bounding rectangle of a given window, including the title bar, border, and scroll bars, if present. You can use the GetWindowRect, to update the Width and Height properties in a program as the properties change in the Resize event of the MDIForm.

The following example demonstrates this workaround:

 Run Visual Basic, or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default. Set the MDIChild property to True for Form1. From the File menu, choose New Module (ALT, F, M ). Module1 is created by default.  Add the following code to the General Declarations section of Module1: Declare Sub GetWindowRect Lib &quot;USER.EXE&quot; (ByVal h%, rect As Any) Type RectShort X As Integer y As Integer dx As Integer dy As Integer End Type  From the File menu, choose New MDI Form (ALT, F, I ). MDIForm1 is created by default.  Add the following code to MDIForm1's MDIForm_Resize event procedure: Sub MDIForm_Resize Dim rect As RectShort

Call GetWindowRect(Me.hWnd, rect)

If (rect.dx - rect.X) * Screen.TwipsPerPixelX <> Width Then Me.Width = (rect.dx - rect.X) * Screen.TwipsPerPixelX End If

If (rect.dy - rect.y) * Screen.TwipsPerPixelY <> Height Then Me.Height = (rect.dy - rect.y) * Screen.TwipsPerPixelY End If

End Sub </li>  Add the following code to the Form1_Click event: Sub Form1_Click Print &quot;Width = &quot;; Format$(MDIForm1.Width) Print &quot;Height = &quot;; Format$(MDIForm1.Height) End Sub </li> From the Run menu, choose Start (ALT, R, S) to run the program.</li> Using the mouse, grab the lower right-hand corner border of MDIForm1. Resize it so that the MDIform is taller and wider than its current size.</li> Click the command button.

At this point, the current Height and Width properties for MDIForm1 are printed on Form1.</li> Repeat steps 9 and 10.</li></ol>

The current Height and Width properties for MDIForm1 are printed on Form1 reflecting their new values.

<div class="status_section">

STATUS
Microsoft has confirmed this to be a problem in both the Standard and Professional Editions of Microsoft Visual Basic version 2.0 for Windows. This problem was corrected in Microsoft Visual Basic version 3.0 for Windows.

<div class="moreinformation_section">

Steps to Reproduce Problem
<ol> Run Visual Basic, or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.</li> Set the MDIChild property to True for Form1.</li>  Add the following code to Form1's Form_Click event procedure. Sub Form_Click Print mdiform1.Width, mdiform1.Height Print mdiform1.ScaleWidth, mdiform1.ScaleHeight End Sub </li> From the File menu, choose New MDI Form (ALT, F, I ). MDIForm1 is created by default.</li> From the Run menu, choose Start (ALT, R, S) to run the program.</li> Use the mouse and click Form1.

The Width and Height property values for Form1 are printed on the first line of Form1, and its ScaleHeight and ScaleWidth are printed on the second line.</li> Use the mouse to grab the lower right-hand corner border of MDIForm1. Resize it so that the MDIform is taller and wider than the default size it had originally.</li> Using the mouse, click Form1.</li></ol>

The Width and Height property values for Form1 are printed on the third line of Form1, and its ScaleHeight and ScaleWidth are printed on the fourth line.

As expected, the ScaleHeight and ScaleWidth values on the fourth line are larger than their corresponding values on the second line. The Width and Height properties on line three, however, are identical with line one. Like the ScaleHeight and ScaleWidth, the Height and Width values should change reflecting the form's new size.

Additional query words: buglist2.00 fixlist3.00 2.00 3.00

Keywords: kbbug kbfix KB96097

-

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

© Microsoft Corporation. All rights reserved.