Hi Peter,
> public override bool CanBeParentedTo(IDesigner parentDesigner)
This method is never called when the item is dropped from the Toolbox. You
may not override this method.
> How should i control adding a control from the ToolBox ??
In the designer class (which must derive from ParentControlDesigner instead
of directly ControlDesigner), override the method "CanParent" method.
The functionality is similar to that of CanBeParentedTo but the reverse way
(CanParent instead of CanBeParentedTo).
Override both overloaded forms, in CanParent(ControlDesigner designer), you
may have just one line code:
CanParent(designer.Control);

Signature
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://webservices.edujini.in
-------------------
Peter Larsen - 31 May 2006 08:29 GMT
Hi Gaurav Vaish,
Thanks for your comment.
CanParent control which controls that is dropped on itself. This is not what
i want here.
If i want to use CanParent, then i must add CanParent to all controls on the
form so it is capable of rejecting my UserControl picked from the ToolBox
(except where it is allowed).
I want CanBeParentedTo - and i'm already using it - but as you said,
CanBeParentedTo does not catch the event when you drop a control from the
TollBox.
So what am i going to do ??
CapParent and ControlAdded together catch all events related to adding a
control to itself.
CapBeParentedTo and "something unknown" together should be able to catch all
events when the control itself is being placed on a parent.
BR
Peter
Peter Larsen - 31 May 2006 09:04 GMT
Hi,
I think i have found that ParentChanged does the trick:
void theControl_ParentChanged(object sender, EventArgs e)
{
if (theControl.Parent != null)
{
if (! (theControl.Parent is Panel) )
throw new ApplicationException("This control is not
allowed on " + theControl.Parent.ToString() + '\n');
}
}
BR
Peter
Gaurav Vaish (www.EduJini.IN) - 01 Jun 2006 20:37 GMT
> void theControl_ParentChanged(object sender, EventArgs e)
Hmmm... should have thought about it long back.
Silly me. :D

Signature
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
http://webservices.edujini.in
-------------------