There are two parts to this code..
one is in the form itself and the other is in a module
Be Aware that this code will resize all the controls except a check box,combobox,listbox and your text size. However with a little manipulation I am sure you can write a routine for the text..if you do..let me know, I am still trying to do that.
put this code into the form you want to resize
************Start Form Code***************
Option Explicit
Private mintSaveWidth As Integer
Private mintSaveHeight As Integer
'additional vars for min and max
Dim intMinHeight As Integer, intMinWidth As Integer
Private Sub Form_Activate()
'Save Last height and width
mintSaveWidth = Me.Width
mintSaveHeight = Me.Height
End Sub
Private Sub Form_Load()
'Get the form min height and width
'Assume the programmer correctly sized the form initially
intMinHeight = Me.Height
intMinWidth = Me.Width
End Sub
Private Sub Form_Resize()
If (Me.Height >= intMinHeight) And (Me.Width >= intMinWidth) Then
ResizeControls Me, mintSaveWidth, mintSaveHeight
Else
'Force the form back to its last size
Me.Width = mintSaveWidth
Me.Height = mintSaveHeight
End If
End Sub
***************End Form Code*********************
then put this code into your module..then modify as you wish
Public Sub ResizeControls(frm As Form, oldWidth As Integer, _
oldHeight As Integer)
'Resize and readjust positions of all controls on the form
'Don't try to adjust minimized form.
If oldWidth < 1 Or oldHeight < 1 Then Exit Sub
Dim ratioW As Single, ratioH As Single
ratioW = frm.Width / oldWidth
ratioH = frm.Height / oldHeight
On Error Resume Next
Dim ctrl As Control
For Each ctrl In frm.Controls
With ctrl
.Width = .Width * ratioW
.Left = .Left * ratioW
.Height = .Height * ratioH
.Top = .Top * ratioH
End With
Next ctrl
That depends on your form's design. Here's how I handle it, 2 ways:
1) Use constant margin/s in between controls, horizontally and vertically. When resizing horizontally, move/resize controls on the rightmost first so you can use its Left property to use for the next control. When resizing vertically, move/resize controls on the bottom first so to be able to use the Top property.
2) Resizing by percent, not exceeding 100%, useful for grid controls.
One setback though, the more controls you resize, you'll experience refresh delays when resizing your form.
As always, that depends on how you designed your form. As to what event, under Form_Resize() event (by zgtrman)
Hope this helps.
As you resize, you may need to watch for fontsizes as well.
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'People who live in windowed environments shouldn't cast pointers.'
At least at a glance, the code from zgtrman shouldn't do anything (at least re re-sizing form/controls), unless the USER manually re-sizes the Form by dragging the boarder.
In the activale and load procedures, only the current dimensions are saved to local variables.
The resize event code doesn't activate unless / untill the form is manually (drag the boarder) re-sized.
While Lothster did not specify the process for the re-sizing "event", a more common approach would be to 'assume' the goal is to re-size all forms to the screen resoloution available on a specific machine, to have the same (viewing) capability on all machines running the app.
Resize Event
Occurs when an object is first displayed or when the window state of an object changes. (For example, a form is maximized, minimized, or restored.)
I was referring to the following statement:
"The resize event code doesn't activate unless / untill the form is manually (drag the boarder) re-sized."
That worked perfectly... almost..
I also have a sstab control in there, but only the controls on the currently selected tab get resized properly... the rest of them on the other tabs just dissapear.
I'm currently working with it and should be able to figure it out, but any shortcuts would be greatly appreciated once again. Thanks.
Lothster.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.