hi there!! i'm having problem with my winforms.

because when i run it at a different computer's resolution it doesn't look like the one i made.

like for example, i build it using a 1280X1024 hence it runs fine at using this resolution but when i run it on a 800X600, the forms is too big.

how could i make the forms cope up with the resolutions???

Dani AI

Generated

This thread is really about layout strategy more than an operating-system bug. Useful pointers above from (check the display bounds at runtime) and (favor docking/panels over absolute placement) are on target, but a short, practical checklist and a couple of techniques will make WinForms robust across resolutions and DPI settings.

Use container controls and percent-based layout so positions scale instead of staying at fixed pixels. Prefer TableLayoutPanel or FlowLayoutPanel and set ColumnStyle/RowStyle to Percent so child controls resize proportionally. Keep edge controls in small docked/anchored panels and enable AutoScroll on the main area so content never becomes unreachable. See Microsoft guidance on docking and anchoring for the behavior and designer options. (learn.microsoft.com)

Automatic scaling and DPI awareness are a second axis: WinForms can scale by Font or DPI, and newer .NET versions have improved per-monitor DPI support, but that requires opt-in. If the app targets older frameworks (VS 2005 era), expect to handle some scaling manually; on newer frameworks use the platform features and app configuration flags described in the Windows Forms high-DPI docs. For general autoscaling behavior and pitfalls (mixing modes can break derived forms) see the Automatic Scaling and High DPI docs. (learn.microsoft.com)

Two small, practical examples:

  • TableLayoutPanel percent columns (designer or code) keeps layout proportional:

    var tbl = new TableLayoutPanel { Dock = DockStyle.Fill, ColumnCount = 2 };
    tbl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 70));
    tbl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30));
  • If you must programmatically scale at startup (designWidth = 1280 here), compute a uniform factor and call Form.Scale:

    float factor = Math.Min(screenWidth / (float)designWidth, screenHeight / (float)designHeight);
    this.Scale(new SizeF(factor, factor));

Final checklist: design to your minimum supported resolution, prefer percent layouts, test with different system font sizes and DPIs, set sensible MinimumSize and AutoScroll, and use SuspendLayout/ResumeLayout when doing bulk runtime changes. These steps will keep buttons visible and controls usable across machines. (learn.microsoft.com)

Recommended Answers

All 6 Replies

You have a Screen cass which exposes a property GetBounds.
You can use it to set the size of your form.

how can i do this??? is there a certain code for it??

I assume you are using C# 2008 VS express.
Then use this call :
Rectangle r = Screen.GetBounds(myform);
This does not give you the bounds of your form but it gives you the bounds of the screen your form wants to live in.
Now r contains all the elements to adjust the size of your form.

commented: Danny you're very nice, truly +6

I'm not using c# 2008 i'm using c# 2005 standard edition.

I used

this.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;

the form was successfully changed according to the computer's resolution but the contents isn't. like the content was ruined

like when a button was supposed to be located at the down left corner of the form,it isn't displaying at its position anymore(can't see it)because of the high resolution(800X600 from 1280X1024).

how can i make the content fit the changed resolution?

Perhaps have a look at the Anchor property of your controls?
Or make your design fit for the lowest resolution. It makes no sense to have a screen 100 high 100 wide and have a button placed at location 1000,1000

This is really a question of layout more than resolution, the resolution is what causes the design error to manifest itself. Other settings such as enabling large font support cause a windows form to be drawn "bigger" than it normally would, for which there is no fix (because there shouldn't be).

What you can do is lay everything out in panels and dock them. Have the button that should be in the lower left in a panel that is docked to the right on the form, that way the main area of the application would appear shorter and get a scrollbar but the button would still be visible.

Anchoring is handy to guarantee a certain distance from the parent container, but the parent container should always be docked to assure its' visibility.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.