Adding a panel

  • Thread starter Thread starter Anders Eriksson
  • Start date Start date
A

Anders Eriksson

Hello!

How do I add a panel and get the already existing controls to be included
in the panel?

The only way I have made it work if I create the panel first and then add
the other controls. But often I don't realize that I need to use a panel
until I have done much work and already have controls on the frame.

// Anders
 
You can dinamically add controls to an existing panel using panel's property
Controls.

Panel p = new Panel();
TextBox text = new TextBox();
p.Controls.Add(text);
 
If you are referring to working with the controls in the the visual designer
for Windows Forms, then this is very easy to do. Just select all the
pertinent controls, then drag them as a group into the Panel control. They
will re-parent to the Panel. Alternately, you could cut-and-paste the
controls as well.
 
Back
Top