Can I create a custom control with a designer like a form designer

Can I create a custom control with a designer like a form designer

Post by dHJhbn » Thu, 24 Dec 2009 04:23:01


Using Visual Studio 2008, is there anyway I can create a custom control which
is comprised of several standard windows controls put together in a certain
way?

For example, I want to have a panel, and inside this panel will be a few
other Panels with other controls within these panels. I want to position
them, set their docking and create a basic interface which would be grouped
together as one component.

Then I would want to go back to my main app and be able to add these
components throughout my app - just drag n drop in on some location set it's
docking and be done, so I dont have to recreate the whole component
repetively every time I need it.

Now, the standard "Designer" I get for my custom controls as far as I can
tell only allows me to drag n drop controls into a screen but it does not
render them and let me resize them and place other controls within them. For
example, I drag a Panel over and I just get some icon for the panel and it
says "panel1" but I cannot size it, position it etc...

How can I do this?
 
 
 

Can I create a custom control with a designer like a form designer

Post by Peter Duni » Thu, 24 Dec 2009 04:33:28


I'm not entirely sure I understand your description. The last paragraph
is a bit confusing. But based on everything else you wrote, it seems to
me that you probably just need to use a UserControl-derived class. Just
use the "Add Item..." command for the project, and select "User Control"
(it's in the same place you'd add a new form, just a different item).

The UserControl class is a lot like a Form, in the way it works in the
Designer. The main difference is that when compiled, it will then show
up in the Toolbox, from which you can drag the control to get a new
instance into a form, just like any other control type.

(You can actually also compile a UserControl into a DLL for reuse in
other projects. When you add the DLL containing the UserControl as a
reference for the other project, the UserControl then becomes available
in the Toolbox as noted above).

Pete