FIX: Resizing MDIForm with UI Does Not Update Height & Width (96097)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition for Windows 2.0
- Microsoft Visual Basic Professional Edition for Windows 2.0
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 "USER.EXE" (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
- Add the following code to the Form1_Click event:
Sub Form1_Click ()
Print "Width = "; Format$(MDIForm1.Width)
Print "Height = "; Format$(MDIForm1.Height)
End Sub
- From the Run menu, choose Start (ALT, R, S) to run the program.
- 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.
- Click the command button.
At this point, the current Height and Width properties for MDIForm1 are
printed on Form1. - Repeat steps 9 and 10.
The current Height and Width properties for MDIForm1 are printed on Form1
reflecting their new values.
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.
Modification Type: | Major | Last Reviewed: | 10/30/2003 |
---|
Keywords: | kbbug kbfix KB96097 |
---|
|