FIX: Resizing MDIForm with UI Does Not Update Height & Width
ID: Q96097
|
2.00
WINDOWS
kbprg kbbuglist
The information in this article applies to:
-
Microsoft Visual Basic Standard and Professional Editions for Windows, version 2.0
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.
MORE INFORMATIONSteps to Reproduce Problem
- 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.
- 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
- From the File menu, choose New MDI Form (ALT, F, I ). MDIForm1 is
created by default.
- From the Run menu, choose Start (ALT, R, S) to run the program.
- 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.
- 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.
- Using the mouse, click Form1.
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 :
Version : WINDOWS:2.0
Platform : WINDOWS
Issue type :
|