Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place a new panel underneath existing controls?

This happens a lot: I have a lot of controls laid out, and I decide I'd like to put them into a panel for whatever reason -- maybe to make it easier to disable them all at once without affecting other controls, or to isolate some radio buttons, etc.

I find it a cumbersome operation to add a System.Windows.Forms.Panel "beneath" my controls. This usually involves resizing my parent control or form so I can add the panel in a temporary space adjacent to the collection of controls that will soon occupy the panel, then dragging the controls onto the panel, then setting the parent control/form size back to what it was before.

Often I have anchors set in various ways on various controls so that simply resizing the parent doesn't happen without the carefully-tweaked layout of the controls getting all messed up.

This is obviously a tedious process for what should be such a simple operation. Is there a VS trick to doing this (other than editing the designer-generated file by hand, which would mean I'd have to hand-pick the controls by name that I want to re-parent)?

like image 289
rory.ap Avatar asked May 30 '14 13:05

rory.ap


People also ask

How do you install a control panel?

Add other controls to the panel, drawing each inside the panel. If you have existing controls that you want to enclose in a panel, you can select all the controls, cut them to the Clipboard, select the Panel control, and then paste them into the panel. You can also drag them into the panel.

Which layout control can set the property of control at run time?

The TableLayoutPanel control arranges its contents in a grid. Because the layout is done both at design time and run time, it can change dynamically as the application environment changes.


1 Answers

Matt has a pretty good answer but this might be a little easier.

Place a panel on your form and set Dock to full. You will not be able to see any of your controls. Then open the Document Outline for the form. Drag and drop each control onto Panel1. Each control will land right where you want them to be. Now if you wanted to, you could disable all controls in the panel by simply setting Panel1.Disabled = true.

If there are controls that you don't want to have as part of the panel. Select the control in the Document Outline and choose Bring to Front. This control will be visible and not affected by setting the panels Enable property.

like image 81
Dave Hampel Avatar answered Oct 30 '22 08:10

Dave Hampel