Reputation: 731
How can I make two controls share the same height. I have set the Size to be the same for both controls but when I run it, I am seeing a difference.
this.txtUserName.Size = new System.Drawing.Size(382, 45);
this.btnLogin.Size = new System.Drawing.Size(75, 45);
Upvotes: 0
Views: 79
Reputation: 54433
Actually both have the same Height
as you set them. However in order to accomodate various BorderStyles
(or FlatStyles
as it is called in the case of Buttons
) the full size is not always visible.
So, the Button
will look to be one pixel smaller on each side than the Height
is has with these (current) appearances:
button1.FlatStyle = FlatStyle.Standard
button1.FlatStyle = FlatStyle.System
The full Size will be visible with
button1.FlatStyle = FlatStyle.Popup
button1.FlatStyle = FlatStyle.Flat
If you are sure about your choice of FlatStyle
you may want to adapt their Height (and Location!) accordingly..
To further complicate thing the TextBox
's visible Height will change if you set its BorderStyle from FixedSingle
or Fixed3D
to None
: It will shrink by 7 (!) pixels..
Note that as far as I remember, all those details of the borderstyles depend on the Windows version & Visual Styles on the target machine.. I am running W8.1 here
Upvotes: 1
Reputation: 20842
Open the Form.Designer.cs and go to InitializeComponent() method for the form, you'll see initialization code for all components on the form.
If you are setting these values prior to InitializeComponent() call from the constructor, it'll be lost. Otherwise you may need to check Margin and Padding of the components.
http://msdn.microsoft.com/en-us/library/vstudio/ms229627(v=vs.100).aspx
Upvotes: 0