Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How to Reize automatically form control according to screen resolution
Posted
Comments
Sergey Alexandrovich Kryukov 18-Jan-11 10:18am    
WinForms, WPF, APS.NET..?

You will find the resolution using the Screen[^] class.

Or you can set the WindowState[^] property to FormWindowState.Maximized

Regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Jan-11 10:17am    
Sure - a 5.
I would not answer because it is not specified WinForms or WPF or ASP.NET
Espen Harlinn 18-Jan-11 11:02am    
Thank you SAKryukov
basically anchor and dock properties is used to resize control according to screen resolution but in case you have lots of control in your form then..
The best way to use Tablelayout,Flowlayout panel because of its feature The FlowLayoutPanel control and the TableLayoutPanel control provide intuitive ways to arrange controls on your form.
The TableLayoutPanel control provides a proportional resizing capability at run time, so your layout can change smoothly as your form is resized as well as All the controls are anchored to all the sides of cell in which you keep them.
In short I will suggest you to When you need a dynamic layout and you do not want to handle Layout events explicitly in your code, thn you should consider using a layout panel.
to know how to use panels go there[^]
 
Share this answer
 
Comments
Espen Harlinn 18-Jan-11 6:42am    
5+ Good answer, this is a nice way to organize the contents of the Form
RaviRanjanKr 18-Jan-11 11:36am    
Thanks Espen
Sergey Alexandrovich Kryukov 18-Jan-11 10:15am    
I would say: use Dock and padding, and, typically, no anchors -- harder to support, tend to cause flicker of resize.
use Anchor and dock properties for resizing the controls
Find More[^]
 
Share this answer
 
The other answers here assume you are talking about changing the size of elements of a Form, but your question as asked does not ask about that: it asks about changing a Form based on screen-resolution.

And the fact is: when you change screen resolution, the entire Form is going to change and become larger, or smaller (perhaps scaled horizontally or vertically in a way you don't want depending on differences in aspect ration between resolution choices).

If your question is about how to change the size of elements on a Form when window size is changed at run-time in the context of one screen-resolution: that's a different question.
 
Share this answer
 
In addition to finding the answers added here based on evident "psychic powers" in reading the OP's mind ... the OP clearly speaking of changing "screen resolution" ... about as useful as astrology ... I feel compelled to add:

A comment on this statement by SA Kruykov above: "I would say: use Dock and padding, and, typically, no anchors -- harder to support, tend to cause flicker of resize."

I find that statement possibly confusing to the general reader, and not connected to my direct frequent experience in designing complex Windows Forms that use Anchor and Dock. Personally I've had no problem with "flicker" using Anchor, but then I am careful in any Form SizeChanged Event to suspend and resume Layout of the Form, use double-buffering, etc.

Dock and Anchor properties interact: to set one most often changes the other. But, any "Dock" setting essentially over-rides whatever Anchor settings there are. And, changing one Anchor setting, with a Dock setting in place, will reset the Dock to 'None.

The Padding of an"outer" container will, of course, affect the placement of Controls within it. You'll note that a WinForm has a Padding property, but, as you would expect, no Margin property.

Imagine two controls docked together in the same "container" ... let's say both Docked 'Top ... the bottom edge of the first Docked Control added, and the top edge of the second Docked Control added, will be "locked" together.

The Margin properties of both Docked Controls will be ignored, and their respective bottom and top edges will remain congruent ("joined," or "flush").

On a practical basis this prevents an easy creation of a series of ordered inner containers (all docked Top, or whatever) that are separated visually by some space between them. That's often desirable from a UI design point of view.

Yes, there are work-arounds for this, but they are a pain in the butt, and I believe if the Dock facility were designed properly, it would allow the Margin settings of "adjoining" Controls that shared a similar Dock Property to work as you might expect.

Well, you might say, "put up or shut up:" what are the work arounds:

1. set a borderstyle : single or 3d : butt-ugly !

2. vary the color of the series of Docked Controls: ho-hum !

3. get into custom painting of an inner border: yuck !

4. insert dummy Controls to function as separators: abomination !

5. do the right thing to make each Control to be Docked embedded within a Panel whose background color matches the background color of the container, and then use the 'Margin property of the Panel that contains the Control to create the illusion of space between Docked Controls: imho the better solution, but too much work !

I consider the mutual interaction(s) of Dock, and Anchor, and the anomaly of setting Dock wiping out Margin settings a great weakness in the design of the WinForms UI in VS.

This is only one example of the problems in using Dock and/or Anchor.

Let the down-votes begin from those who "do not have ears to hear" :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900