How to adjust button's location
-
How can I add a button when run time? and if there is a button in the form, how can it added next to it? Could you help me,please? Thanks in advance.
drago123 wrote:
How can I add a button when run time?
You just create the button and add it to the forms
Controls
collection.Button b = new Button();
this.Controls.Add(b);drago123 wrote:
and if there is a button in the form, how can it added next to it? Could you help me,please?
You need to work out the position of the existing button, and position your new button alongside it.
// Set the left position to be the same as the existing button.
int left = existingButton.Left;
// Plus the width of the existing button.
left += existingButton.Width;
// Plus a small gap.
left += 20;// Set the top of the new button to be the same as the existing button.
int top = existingButton.Top;// Create the new button.
Button newButton = new Button();// Assign the left & top values to position the button.
newButton.Left = left;
newButton.Top = top;// Add the new button to the controls collection.
this.Controls.Add(newButton);That help?
Simon
-
drago123 wrote:
How can I add a button when run time?
You just create the button and add it to the forms
Controls
collection.Button b = new Button();
this.Controls.Add(b);drago123 wrote:
and if there is a button in the form, how can it added next to it? Could you help me,please?
You need to work out the position of the existing button, and position your new button alongside it.
// Set the left position to be the same as the existing button.
int left = existingButton.Left;
// Plus the width of the existing button.
left += existingButton.Width;
// Plus a small gap.
left += 20;// Set the top of the new button to be the same as the existing button.
int top = existingButton.Top;// Create the new button.
Button newButton = new Button();// Assign the left & top values to position the button.
newButton.Left = left;
newButton.Top = top;// Add the new button to the controls collection.
this.Controls.Add(newButton);That help?
Simon