Resizing forms at runtime 
Author Message
 Resizing forms at runtime

If I have a form with controls on it and allow the user to maximize the
form what do I have to do to then have the controls spread out over the
entire form and not just stay in the corner where they began. I hope
this is clear.


Sat, 24 May 2003 03:00:00 GMT  
 Resizing forms at runtime
Jeff,

Here's working code that keeps a control mapped to the form as it's resized.
It also deals with minimized forms.

' (General) (Declarations)
' API Interface Functions and Data types
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long,
lpRect As RECT) As Long

Private Sub Form_Resize()
  Dim WindowSize As RECT

  If GetClientRect(Me.hwnd, WindowSize) <> 0 Then
    ImgEdit1.Height = WindowSize.Bottom * Screen.TwipsPerPixelY
    ImgEdit1.Width = WindowSize.Right * Screen.TwipsPerPixelX
  End If

  ' Adjust top for toolbar
  If tbToolBar.Visible = True Then
    ImgEdit1.Top = tbToolBar.Height
  Else
    ImgEdit1.Top = 0
  End If
  ' Adjust height
  ImgEdit1.Height = Abs(ImgEdit1.Height - ImgEdit1.Top)
  If sbStatusBar.Visible = True Then ImgEdit1.Height = ImgEdit1.Height -
sbStatusBar.Height
  ImgEdit1.FitTo 0
End Sub


Quote:
> If I have a form with controls on it and allow the user to maximize the
> form what do I have to do to then have the controls spread out over the
> entire form and not just stay in the corner where they began. I hope
> this is clear.



Sat, 24 May 2003 03:00:00 GMT  
 Resizing forms at runtime
Michael, Jeff

that looks a bit too complicated to me. I see no reason to use the Windows
API here.

The size of the client area is defined by ScaleWidth and ScaleHeight
properties of the form. (The same applies to a user control).

All you have to do is position the controls from within the Resize method,
acording to your personal algorithm. You can either set the Left, Top. Width
and Height properties or the controls or call the Move method. It is more
efficient to call the Move method than to set the four properties
separately.

I find it practical to insert "On error resume next", because it's more
effort than it is worth to make a water tight algorithm. For example, who
cares if the positions are illegal when you minimize the window!

Reply if you need an example, but this really is so simple that you should
manage without.

Phil



Sun, 25 May 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Resize form at runtime?

2. Closing one form from another and resizing the entire form at runtime

3. resizing a form size at runtime

4. VB 6.0 - Forms resize at runtime

5. Resizing Everything when Form Resizes

6. Resizing an object when a form is resized.....

7. resizing a form when a control resizes during execution

8. Resizing components after form resize

9. Resize form - resize controls

10. Correction: Resize form - resize controls

11. resizing DataGrid after resizing Form

12. Resizing a control when the Form is resized

 

 
Powered by phpBB® Forum Software