Using C # WinForms constructor in a panel instead of a form?

Warning: I'm new to creating a GUI in C # (from a long history in Java with Swing and SWT.)

Using VS2008. When I create a new class and extend System.Windows.Forms.Form , WinForms Designer works really nicely. But; when I create a new class and expand System.Windows.Forms.Panel , the designer does not work so elegant - it just shows an abstract view a list of types of components contained in the panel (as opposed to the actual location on the display panel controls.)

Is there any way to get the Designer to work with the panel better?

Or is there some workaround so that I can create a form with a constructor and then use it as if it were just a panel?

What I'm really looking for is some โ€œuser interfaceโ€ element that I can build with a constructor, and then dynamically (read: programmatically) add / remove this โ€œelementโ€ for a larger user interface.

+4
source share
1 answer

I think you are looking for UserControl . You can inherit directly from this, and you should be able to use the constructor to drag and drop on it.

To make this even easier, you can simply right-click on your project and click "Add" - "User Control". This will create a .cs file for you as well as a partial .cs file for the code created by the constructor.

+14
source

All Articles