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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With