Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Forms sizes not matching

I've got some very strict requirements on windows form sizes for elements and I've been having some trouble actually matching that up, I figured out the problem but I don't understand why I'm getting it. I have a picture box that needs to be a specific size, when I set it to that size in the properties panel of visual studio, it doesn't actually take that size, but a value smaller than that. It was throwing off my development. I can rectify it by manually setting the size value in the form code, however I'd like to know why the properties tab doesn't automatically do it correctly. I've just got it outputting the precise size value to a message box.

Actual size

Properties window

like image 527
NathanielJPerkins Avatar asked Feb 09 '23 23:02

NathanielJPerkins


2 Answers

I have noticed the exact same behaviour in my project today. The form and all objects on it hat a certain size, but when run, the size was all different.

After checking the InitializeComponents() I found this line

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

so I checked the according property, and I changed it to "None". Have never actually witnessed this behaviour before, but this did the trick for me. Now the Forms and everything else has the specified size.

like image 97
roland_w Avatar answered Feb 14 '23 11:02

roland_w


The Size is actually size of whole window including the borders of windows form. You can see that the inner portion has exactly 18 pixels less for both width and height. You might calculate the desired width and height to assign to the form. Like if you want 100 x 100 pixel inner window size, you can assign 118 x 118 pixel for the size.

like image 34
NBM21 Avatar answered Feb 14 '23 10:02

NBM21