Reputation: 73
I just designed a windows forms application but when it ran on my friends smaller laptop; the form appeared too big or should i say one had to scroll from left to right or top to down to access various text boxes, buttons etc. I was looking at this SO answer, which showed the following code:
this.WindowState = FormWindowState.Maximized;
I presume this piece of code resides in the specific form constructor ? Would this code solve all my issues? I do not have a smaller laptop currently at my disposal for testing unless i start messing with my own screen resolution.
Upvotes: 2
Views: 14478
Reputation: 7352
I personnaly use TableLayoutPanel
and design my form by defining rows and columns, and setting their heights and widths, some with AutoSize
some with Percent
and some with Absolute
size type according to how I want my form to be shaped. Then I put controls(textboxes, labels, comboboxes) inside of the cells of tablelayoutpanel and set their dock
to Fill
. That's it.
I'm not sure if it is the proper way to go for this job, but for 2 years I've been doing that with no failure. Hope it would help to you too.
Upvotes: 0
Reputation: 23685
The code posted in the accepted anwser of that question needs to be put in form constructor, of course (InitializeComponents) and having a maximized form of course removes a lot of problems about sizing. Anyway, the property:
Screen.PrimaryScreen.WorkingArea
is very useful for form sizing and positioning relative to the current screen size. For example:
this.Width = Screen.PrimaryScreen.WorkingArea.Width / 2;
this.Height = Screen.PrimaryScreen.WorkingArea.Height / 2;
this.Top = (Screen.PrimaryScreen.WorkingArea.Top + Screen.PrimaryScreen.WorkingArea.Height) / 4;
this.Left = (Screen.PrimaryScreen.WorkingArea.Left + Screen.PrimaryScreen.WorkingArea.Width) / 4;
Upvotes: 3
Reputation: 11040
Before setting the WindowState
to Maximized you need your form to be fully resizable.
Shrink your form in VS designer as much as possible, set the Dock, Anchor and Min/Max sizes for each of its components, try to resize it in the designer. Repeat until it resizes well.
You may need to group controls together in Panel
s to control how they resize if the above iteration wasn't enough.
Upvotes: 1