• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

how to auto size the form ?

like this, i already make an exe file.

the problem is my computer setting is not the same with the other person computer. may be he set his computer setting 600 X something.
so how do we ask the form to auto resize it self ?
no need for me to mannually go to that computer and change it pixxel setting.

maybe somebody will get mad ?

how ?
  • 2
1 Solution
You can ask windows how big the screen is, and then size your form accordingly.

For example - to start the application with the form filling the screen do this:

Form1 declarations section:

Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

Private Sub Form_Load()

Dim lWidth As Long
Dim lHeight As Long

    lWidth = GetSystemMetrics(SM_CXSCREEN)
    lHeight = GetSystemMetrics(SM_CYSCREEN)
    Me.Move 0, 0, lWidth * Screen.TwipsPerPixelX, lHeight * Screen.TwipsPerPixelY

End Sub
What are the sizes that you want to resize your form to?

e.g. Always resize form to half of screen size in Form_load:

Private Sub Form_Load()
    Me.Height = Screen.Height/2
    Me.Width = Screen.Width/2
End Sub

'This always centers the form.
' Put this code in form_load event
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
leess's solution resizes your form's height and width and my solution above will center the form with the size size as design size.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now