Windows User Control as a container

S

Sam

Please help!

I want to create a user control that can act as a container for other
controls
(like a panel or a groupbox).
The control will consist of a panel that acts as the container for external
controls plus
some other stuff.
I hoped that all I needed to do would be to implement
System.ComponentModel.IContainer,
and pass everything through to the panel in my user control.
This doesn't appear to work, can anyone help?

Thanks.



Public Class My_Control

Inherits System.Windows.Forms.UserControl
Implements System.ComponentModel.IContainer

...

Public Sub Add(ByVal component As System.ComponentModel.IComponent)
Implements System.ComponentModel.IContainer.Add
Panel1.Container.Add(component)
End Sub

Public Sub Add2(ByVal component As System.ComponentModel.IComponent,
ByVal [name] As String) Implements System.ComponentModel.IContainer.Add
Panel1.Container.Add(component, name)
End Sub

Public ReadOnly Property GetComponents() As
System.ComponentModel.ComponentCollection Implements
System.ComponentModel.IContainer.Components
Get
GetComponents = Panel1.Container.Components
End Get
End Property

Public Sub Remove(ByVal component As System.ComponentModel.IComponent)
Implements System.ComponentModel.IContainer.Remove
Panel1.Container.Remove(component)
End Sub

End Class
 
S

Sam

This doesnt seem to work, and the documentation is useless.
Am I missing something really obvious here?
Does an example exist of creating a user-defined container control?
I've tried searching the internet but the only references I can find are
in expensive .net training courses.




Ken Tucker said:
Hi,

All you have to do is use me.setstyle(ControlStyles.ContainerControl)
to make your control a container.
http://support.microsoft.com/default.aspx?scid=kb;en-us;305079

Ken
--------------------
Sam said:
Please help!

I want to create a user control that can act as a container for other
controls
(like a panel or a groupbox).
The control will consist of a panel that acts as the container for external
controls plus
some other stuff.
I hoped that all I needed to do would be to implement
System.ComponentModel.IContainer,
and pass everything through to the panel in my user control.
This doesn't appear to work, can anyone help?

Thanks.



Public Class My_Control

Inherits System.Windows.Forms.UserControl
Implements System.ComponentModel.IContainer

...

Public Sub Add(ByVal component As System.ComponentModel.IComponent)
Implements System.ComponentModel.IContainer.Add
Panel1.Container.Add(component)
End Sub

Public Sub Add2(ByVal component As System.ComponentModel.IComponent,
ByVal [name] As String) Implements System.ComponentModel.IContainer.Add
Panel1.Container.Add(component, name)
End Sub

Public ReadOnly Property GetComponents() As
System.ComponentModel.ComponentCollection Implements
System.ComponentModel.IContainer.Components
Get
GetComponents = Panel1.Container.Components
End Get
End Property

Public Sub Remove(ByVal component As System.ComponentModel.IComponent)
Implements System.ComponentModel.IContainer.Remove
Panel1.Container.Remove(component)
End Sub

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top