Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C# WinForms Designer on Panel instead of Form?

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

Using VS2008, When I create a new class, and extend System.Windows.Forms.Form, the WinForms Designer works really nicely. However; when I create a new class and extend System.Windows.Forms.Panel, the designer does not work nearly as elegantly - it simply shows some kind of abstract, list-type view of the components contained in the Panel (as opposed to showing the actual layout of the Controls in the Panel.)

Is there a way to get the Designer to work more nicely with a Panel?

Or is there some workaround so that I can build a Form with the designer, and then use it as if it were only a Panel?

What I'm really looking for is some UI 'element' I can build with the designer, and then dynamically (read: programmatically) add/remove that 'element' to a larger UI.

like image 963
Jared Avatar asked Dec 10 '22 21:12

Jared


1 Answers

I think what you're looking for is a UserControl. You can inherit directly from that, and you should be able to use the designer to drag and drop stuff on it.

To make it even easier, you can just right click on your project and click Add -> User Control. That will create the .cs file for you as well as a partial .cs file for the designer generated code.

like image 123
BFree Avatar answered Dec 22 '22 09:12

BFree