Layout ratio difference between Form1.Cs[Design] and . exe

Asked

Viewed 98 times

0

Recently I’m programming a Windowsforms application using c#, and there’s kind of a bug going on with the IDE that leaves the layout ratio different, like in the image below: l

The form on the left side is what the IDE presents me before executing the solution, and the one on the right side is the one generated after the build. If you look closely you will notice some differences in the proportion of the elements between them, even the size of the generated form is different.

I wonder what I can do to leave both in the same proportion, it ends up eluding me at the time of arranging the layout of the form.

  • I noticed that this visual bug happens when I increase the font size of both the label and the button.

2 answers

1

You are using windows Forms so I advise you to use the Anchor property to fix its proportions and distances relative to the form border, if you put the Anchor as top in all your input fields they will keep the vertical distances between them, even if the window is resized.

If you want to study a little more design with windows form there is a youtube channel called C# Ui Academy which teaches various design tricks in windows form, which would give you a better knowledge of the properties putting into practice.

  • I put as top, but even so keeps giving that difference in proportion, it only happens when I increase the font size, I do not understand this.

  • When you increase the font size the inputs adapt to its size, as the inputs increase in size they occupy the space of the margin between them, if you increase them further they would eventually overlap. So if you do not change the font size it will be in the location you have determined. You need the inputs to change the font size?

  • In this case I do

  • But the problem is in the font size of the label, when I increase the size of the label even keeping a viable distance between the label and the text box, the label still gets overwriting the text box.

  • In this case you can keep the distance via code, for example you would put in your code inside some window event :textbox.Left = label.Left + label.Width + 10 so it would keep a distance of 10 pixels even if the label size and position is changed.

0

Note in the method InitializeComponents() if the configuration below has been inserted:

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

Change to:

this.AutoScaleMode =  System.Windows.Forms.AutoScaleMode.None;

I could not simulate the same error in my environment, note if this setting will solve your problem.

I found this solution from this reply (in English)

Smart to have helped. Hug.

  • While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - Of Revision

  • 1

    @Augustovasques thanks for the feedback. I edited this reply to try to improve it. I will pay more attention to the question. Hug.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.