all groups > dotnet windows forms designtime > may 2004 >
You're in the

dotnet windows forms designtime

group:

Is Container? Designer seems to know...


Is Container? Designer seems to know... schneider
5/20/2004 11:03:52 PM
dotnet windows forms designtime:
Anyone know how to determine if a control is a container control?

Panel, Form, GroupBox, ..

Some inherit from ScrollableControl but groupbox does not...

I want to know if a control was intended to be used as a container.

Thanks,

Schneider

Re: Is Container? Designer seems to know... schneider
5/21/2004 12:00:23 PM
Well VS designer seems to know the GroupBox is a intended designer...

I know to make a control container you use the SetStyle() method.

But from a external assem/code GetStyle() is not available.

There must be a way since VS can do it...

Schneider
Re: Is Container? Designer seems to know... Kent Boogaart
5/21/2004 6:26:19 PM
Hmmm, short of compile-time checks such as:

if ((control is GroupBox) || etc

there doesn't appear to be a way. The Control.HasChildren property will tell
you whether that control has children but it won't tell you whether the
control was designed to contain children.

My initial thought was to do something like:

if (control is IContainer) {
//...
}

but GroupBox doesn't implement the IContainer interface.

Perhaps someone else has some suggestions on this one...

Kent

[quoted text, click to view]

Re: Is Container? Designer seems to know... Tom McDonnell
5/22/2004 12:08:48 AM
Problem is, the Control class, and any derived class was intended to
contain other controls. It's more the behaviour of the controls designer
that determines if it appears like it was intended to be used as a
container.

[quoted text, click to view]
Re: Is Container? Designer seems to know... schneider
5/26/2004 4:13:05 PM
[quoted text, click to view]

I'm not using any of the MS designer objects right now. Last I checked
the model would not for a component design. This is a drop on the form
component, and provides a advanced end-user designer.

The following code seems to be working for me.

anyway,
Thanks everyone for the help, was a bit stump on the container thing..

Schneider


This is working for me thanks to (Claes Bergfall):

'------------------------------------------------------------
Call GetStyle(ContainerControl) on it. Since it's protected you'll have
to use reflection to do it. This should do it:

Private Overloads Function GetStyle(ByVal ctrl As Control, ByVal style As
ControlStyles) As Boolean
Dim flags As BindingFlags = BindingFlags.NonPublic Or
BindingFlags.Instance
Dim types() As Type = {GetType(ControlStyles)}
Dim methodInfo As MethodInfo
methodInfo = ctrl.GetType.GetMethod("GetStyle", flags, Nothing, types,
Nothing)
If methodInfo Is Nothing Then
Throw New MissingMemberException
Else
Return CBool(methodInfo.Invoke(ctrl, New Object() {style}))
End If
End Function

Re: Is Container? Designer seems to know... Tom McDonnell
5/26/2004 9:28:58 PM
With the GroupBox, using reflection you could get it's designer and see
that it derives from ParentControlDesigner giving it's 'container' like
behaviour. The designer for Form and panel also derive from
AddThis Social Bookmark Button