On Fri, 01 Aug 2008 07:31:51 -0700, Andrew <an****@yahoo.comwrote:
[...]
What I'd do in Delphi is create the Diagram control first from a TPanel
control. I would then write the Activity controls from TComponents. In
the
constructor for the Activity controls I would check and see if the
partent
was a Diagram control. If it was not, I would display a message then
have
the Activity control commit suiside.
I'm just not sure when the parent is assigned if C# and if the
constructor
is the best place to check the parent class in C#.
I question the wisdom of designing the control so that it may only have
some specific type of control as its parent. IMHO, it's much better to
define some specific set of functionality that the parent is required to
have and check for that as needed.
That said, in .NET, the control's parent is not known during construction,
and in fact the parent can change over time (that is, some code could
specifically move the control).
The most appropriate place to check for some qualification of the
control's parent would be in the OnParentChanged() method. Override that,
and respond in whatever way is appropriate for your code if the new parent
isn't qualified. IMHO, all you really should do is throw an exception
(e.g. InvalidOperationException), but I suppose you could actually have
the control remove itself from the new parent and dispose itself (but
there's not really a good way for the control to inform its parent,
especially a parent that wasn't the right parent, to be aware of this...so
I'd really recommend against it).
This is all just for completeness. I want to design a set of controls I
can
use over and over again and pass on to others in our group.
Personally, I'd avoid trying to enforce a specific parent. But if you
really insist, hopefully the above would be helpful information.
Pete