Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making WinForm size (width) dynamic

Status
Not open for further replies.

kpobar

Programmer
Jul 10, 2007
10
US
Hello there... we are developing a WinForm app using C# in VS2005 and have hard-coded the width of each form to be 1024. Fixing the width forces users to a minimum resolution and leaves empty space on the screen if the user has a resoltion higher than 10x8. Has anyone worked with WinForms to make them dynamically size the width based on the user's resolution?

Thanks!
 
If you want to force it to be the max resolution then you can do two things:

1. When the window style property changes set it back to Maximized.

2. Set the minimum form size to Screen.PrimaryScreen.Size


Why exactly are you forcing your users to do this?

 
We don't want to force them into any screen resolution. That is why we are hoping to make the display of the WinForm more dynamic.

Not sure what you mean by "force it to be max resolution"... when a user's screen resolution is 800 x 600, since the form is set to be 1024 x 768, the user does not see the whole form, and in fact is blocked from scrolling horizontally. If the user's screen resolution is greater than 1024 x 768, the application fills the whole screen as it is maximized, but the form itself is still only 1024 x 768, so there is free space to the bottom and to the right of the form. How can we get the form itself to expand and provide more real estate for the form's controls to use?
 
Right on... will investigate. Thanks!
 
Your problem is not about Docking and Anchor. That comes in play when you let the user resize the form, So how will the controls move and resize depends upon the above.
Your problem is about Screen Working area.
The below code is not exact solution to your problem but will take you on the right track.
int i = Screen.GetWorkingArea(this).Height;
int j = Screen.GetWorkingArea(this).Width;

Get the working area and resize your form on load.
And set the window state
this.WindowState = FormWindowState.Normal;

I hope this helps.
Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top