Best way to resize form/controls according to resolution?

33,740

Solution 1

You can get the current screen dimensions with the following:

Dim screenHeight As Integer = My.Computer.Screen.Bounds.Height
Dim screenWidth As Integer = My.Computer.Screen.Bounds.Width

As for resizing, if you anchor your controls to the form you should be able to re-size the form to fit the dimensions of the screen as obtained above.

Solution 2

You can put all of the controls in a TableLayoutPanel, anchor everything correctly, and resize the window to an appropriate size for the display resolution. The controls will resize with the window if you anchor the entire panel on top, bottom, left, and right, and anchor individual text boxes, combo boxes, etc., within the cells.

Takes a little work to figure out how you want things to resize and move around, but not that much.

You can figure out what fraction of the screen you want to take up with your window after getting the numbers from TLiebe's method.

Solution 3

You can anchor the controls in a form to the top, bottom, left or right. This makes it possible to design the form so the size can change without messing up all the controls. You can do this in Design Mode, setting the anchor property of each control.

There is a minimum (and maximum) size property for the form you can use to keep it from getting too small for its controls. You can use Screen.PrimaryScreen.Bounds or My.Computer.Screen.Bounds to get the screen size and set the form size accordingly, or possibly maximize the form if the screen is below a certain size.

Share:
33,740
nishanth
Author by

nishanth

I code stuff

Updated on October 12, 2020

Comments

  • nishanth
    nishanth over 3 years

    I was an idiot and designed my VB app on a 17inch monitor in a 1280X1024 resolution completely forgetting about what it would like on another machine. This might be a long shot, but is there an easy way to get the resolution of the users monitor and re-size the controls and form accordingly?

    Thanks in advance.