Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / May 2004

Tip: Looking for answers? Try searching our database.

Is Container? Designer seems to know...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
schneider - 21 May 2004 05:03 GMT
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
Kent Boogaart - 21 May 2004 09:56 GMT
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

> Anyone know how to determine if a control is a container control?
>
[quoted text clipped - 7 lines]
>
> Schneider
Tom McDonnell - 21 May 2004 15:38 GMT
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.

> Anyone know how to determine if a control is a container control?
>
[quoted text clipped - 7 lines]
>
> Schneider
schneider - 21 May 2004 18:00 GMT
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
Tom McDonnell - 26 May 2004 12:58 GMT
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
ParentControlDesigner.
schneider - 26 May 2004 22:13 GMT
> 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
> ParentControlDesigner.

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

    /claes

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.