Custom control container behavior in designer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey, created a custom control that includes a panel. I want to use the panel
as a container for other controls I drag into the custom control in designer.
I can't seem to find any information on how to do this. I've extended
UserControl and SetStyle containercontrol to true, but this doesn't work. I
think I'll have to trap for drag/drop events, test to see if I'm in the
design environment, cast the drag/drop object to a control and then stick it
in the panel. I'm just hoping that there is an easier way....
 
William Sullivan said:
Hey, created a custom control that includes a panel. I want to use the
panel
as a container for other controls I drag into the custom control in
designer.
I can't seem to find any information on how to do this. I've extended
UserControl and SetStyle containercontrol to true, but this doesn't work.
I
think I'll have to trap for drag/drop events, test to see if I'm in the
design environment, cast the drag/drop object to a control and then stick
it
in the panel. I'm just hoping that there is an easier way....

Modify your control to inherit from ContainerControl rather than
UserControl. This will allow it to automatically accept controls dropped
into it. I don't know of any ways of controlling where sub-controls would
exist within your container control. One approach might be to intercept
ControlAdded events and move the controls into your Panel when a new control
arrives. Needless to say you should only hook this up after you've added all
your "internal" controls. You might need some other plumbing to keep the
developer from getting the controls out of your Panel into the actual
control.

One downside of inheriting from ContainerControl is that you lose the funky
UI for the UserControl. What I do is design my control the way I want it and
then change the inheritance away from UserControl. Any time I want to make
changes, I change it back.
 
Aha! I knew there was an easier way! Losing the designer didn't matter, as
it sucked anyhow. I had all my rendering in a user paint event, which didn't
show up at all in the designer...
 
Back
Top