views:

31

answers:

2

Adding some gui modifications and I want to have a button which is 10pixels away from the forms left and right border. With this code the right border of the button is around 20-30 pixel outside the form window. Why is that? How can I position my button to be exactly 10pixels away from the form borders ?

int margin = 10;
meny1 = new Button();
meny1.Top = 50;
meny1.Left = margin;
meny1.Size = new Size(this.Width - (2*margin), 30);
+1  A: 

You should calculate with this.ClientWidth although I would expect the difference to be just the BorderSize, not 20 pixels.

Henk Holterman
Will do that in the future. Thanks
Milan
+1  A: 

Use the Form.ClientWidth. This code worked for me.

button1.Left = 10;
button1.Width = this.ClientRectangle.Width - 20;
Jason Webb
That worked just fine. Didnt even notice there was the client "space". Thank you.
Milan