Reputation: 8302
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.
Upvotes: 2
Views: 36739
Reputation: 305
Here's the code I used to resize my form on loadup
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Me.Height = My.Computer.Screen.WorkingArea.Height
MyBase.OnLoad(e)
End Sub
Upvotes: 0
Reputation: 116
Understanding Anchor.
Create a blank form.
Set the form's size to MyComputer.screen.bounds.area width and height.
Set the form's WindowSize to Maximum.
Place a panel control in the middle.
Put 4 option buttons in the panel, 2 rows each.
Reduce the size of the panel so that the option buttons just fit.
Anchor the panel to all 4 sides of the form.
Start the app and select the minimize button and the form's sides will now be accesible to shrink and stretch.
Begin shrinking the form from any side and notice how the panel's sides move with the direction of the shrinking.
Change the anchoring of the panel to top and left.
If you shrink from the top or left the panel eventually scrolls toward the opposite edge.
If you shrink from the bottom or right the form' edge scrolls toward the panel.
Upvotes: 0
Reputation: 15813
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.
Upvotes: 1
Reputation: 7996
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.
Upvotes: 2
Reputation: 16007
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.
Upvotes: 4