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:

  1. 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.
  2. Set the MDIChild property to True for Form1.
  3. From the File menu, choose New Module (ALT, F, M ). Module1 is created by default.
  4. 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
    					
  5. From the File menu, choose New MDI Form (ALT, F, I ). MDIForm1 is created by default.
  6. 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
    					
  7. Add the following code to the Form1_Click event:
       Sub Form1_Click ()
          Print "Width = "; Format$(MDIForm1.Width)
          Print "Height = "; Format$(MDIForm1.Height)
       End Sub
    					
  8. From the Run menu, choose Start (ALT, R, S) to run the program.
  9. 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.
  10. Click the command button.

    At this point, the current Height and Width properties for MDIForm1 are printed on Form1.
  11. 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 INFORMATION

Steps to Reproduce Problem

  1. 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.
  2. Set the MDIChild property to True for Form1.
  3. 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
    					
  4. From the File menu, choose New MDI Form (ALT, F, I ). MDIForm1 is created by default.
  5. From the Run menu, choose Start (ALT, R, S) to run the program.
  6. 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.
  7. 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.
  8. 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.

Modification Type:MajorLast Reviewed:10/30/2003
Keywords:kbbug kbfix KB96097