Adjust the layout of the Form according to the resolution of the monitor

1

I made a form in fullScreen , where the monitor I use has 23 inches.

But where the feature will be deployed, they use 19 ". When I ran, Form was not the smallest monitor size, and some components were cut.

Is there any way to be responsive according to the monitor or will I have to edit the size of the components?

23

23"

19

19"

    
asked by anonymous 22.11.2017 / 14:41

2 answers

3

Making a responsive way is not difficult. There are several alternatives that can be used (TabbledLayoutPanel, Anchor and Dock Properties of Controls, FlowLayoutPanel and All Together).

I'll give you a small example using the Anchor property of the controls. See below:

TheAnchorpropertyindicatesinwhichdirectionsthecontrolwillbedocked.Forexample,iftheanchorofmycontrolis"Top, Right" this indicates that my control will always maintain the same distance from the top and right edges of the parent's control. All control by default comes with the Anchor property set to "Top, Left", ie it will maintain the relative distance above and to the left.

Followingourexamplewewillmakethe"Go" button always in the upper right corner of the form. For this we will change the Achor property to "Top, Rigth". When you resize the form, it will assume the following behavior:

Thenextstepistomakethetextboxalwayskeepthesamedistancetotheleftastotheright.Forthis,wewillusetheanchor"Top, Left, Rigth":

Finally,wewantthegridbelowtomaintainthesamedistanceinalldirections.Todothis,simplysetAnchoras"Top, Bottom, Left, Rigth".

Ihopethislittleexamplewillhelpyourgoal.ItisworthnotingthatthisAchorpropertycanbedefinedviacodeasbelowwhereIdefine"Botton, Right" in a text field:

 textBox1.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;

Remembering that the anchor (Anchor) is always relative to the parent control. In the example below I set the anchor to all directions in the "Hello" button but since this button has a panel as its parent, it will follow the behavior of the parent.

    
29.12.2017 / 17:04
2
That's just the way it is. WinForms has everything fixed. And most leave it like this.

You can use a flow panel to help you become more" responsive "(put to make fun, I do not like the use of it that word for that). But if you do not know how to do it right the result can get much worse and often not even notice. But you have to change some controls to fit the panel size.

I know there are libraries that help a little more, but I have never used them and it seems to me that they weigh and some are full of problems.

Of course you can also put together your own scheme, but it takes a lot of work to do it right in WinForms, and it tends to go awry if you do not master the subject.

And yes, there are people who prefer to do two different layouts. Not that you need two codes, just parameterize the positions and size of the controls. Of course, like everything else, you need to know how to do it.

With WPF you can do a little better. In fact it can make even more interesting that it is working with \ zoom to fill everything (not that it is useful in all cases).

    
22.11.2017 / 14:50