add button in form

  • Thread starter Thread starter ooooscar
  • Start date Start date
O

ooooscar

How can I add a new button in the form ?. I'd like to have the
maximize,minimize button and a new one made for me to do hide the
application to the task bar.
 
Hi Oscar,

You add a Button object to the Form's Controls collection.

Button b; // button reference
b = new Button(); // create a new button object
// and assign its reference to b
this.Controls.Add(b); // add the button to the form's control collection

The button will now be visible on the Form with the default location and
size. Beware that unless you specify a location for the button any other
button will cover the first button making it disappear.

Replace this. with any other control able to hold controls like panel,
groupbox etc if needed.

GroupBox g = new GroupBox();
this.Controls.Add(g);

Panel p = new Panel();
g.Controls.Add(p);

Button b = new Button();
p.Controls.Add(b);

This will create a Form with a GroupBox, the GroupBox will have a Panel,
and the Panel will have a Button.
 
From the menu View | Toolbox, and drag a button to the forms design surface;
this will automatically add the button to the form's controls collection.
 
Back
Top