Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

You will need to synchronize the panel collection with the Control

collection on the UserControl (that is, when you add to the panel

collection, add to the control collection, when you remove on the

panel collection, remove from the control collection, etc).

 

You can do this by doing Me.Controls.Add(thePanelObject). Then

you will need to manually make each panel visible/invisible when you

want to see them.

Posted

I dont quite get what you mean the Panels will be container as in normal heres the source

 

Imports System.ComponentModel
Imports System.ComponentModel.Design.Serialization

Public Class Pagelist
   Inherits System.Windows.Forms.UserControl

   Private _pagecollection As New PageCollection()
   Private _selectedPage As Panel

   <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
   Public ReadOnly Property Pages() As PageCollection
       Get
           Return _pagecollection
           Invalidate()
       End Get
   End Property

#Region " Windows Form Designer generated code "

   Public Sub New()
       MyBase.New()

       'This call is required by the Windows Form Designer.
       InitializeComponent()
       SetStyle(ControlStyles.AllPaintingInWmPaint, True)
       SetStyle(ControlStyles.DoubleBuffer, True)
       _pagecollection = New PageCollection()
       'Add any initialization after the InitializeComponent() call

   End Sub

   'UserControl overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.IContainer

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       components = New System.ComponentModel.Container()
   End Sub

#End Region

End Class

Public Class PageCollection
   Inherits CollectionBase

   Default Public Property Item(ByVal Index As Integer) As Panel
       Get
           Return DirectCast(list.Item(Index), Panel)
       End Get
       Set(ByVal Value As Panel)
           list.Item(Index) = Value
       End Set
   End Property

   Public Function Add(ByVal Item As Panel) As Integer
       Return List.Add(Item)
   End Function

End Class

'Public Class PageConverter
'    Inherits TypeConverter


'    Public Overloads Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean
'        If destinationType Is GetType(InstanceDescriptor) Then
'            Return True
'        End If
'        Return MyBase.CanConvertTo(context, destinationType)
'    End Function

'    Public Overloads Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object
'        If destinationType Is GetType(InstanceDescriptor) Then
'            Dim cat As Panel = DirectCast(value, Panel)
'            Dim cl As System.Reflection.ConstructorInfo = GetType(Panel).GetConstructor(System.Type.EmptyTypes)
'            Return New InstanceDescriptor(cl, Nothing, False)
'        End If
'        Return MyBase.ConvertTo(context, culture, value, destinationType)
'    End Function

'End Class

 

Cheers

 

Andy

Code today gone tomorrow!
  • *Experts*
Posted

Well, the way I would do it is to store a "ParentUserControl" property

within the PanelCollection. Then, when you create the PanelCollection,

set the ParentUserControl = the UserControl you're using (Me).

Then, in the Add method of the PanelCollection, use

 

_parentUserControl.Controls.Add(myPanelObject)

 

_parentUserControl being the member variable containing the reference

to the parent UserControl.

  • *Experts*
Posted

OK, in your PageCollection class, add a member variable:

Private _parentUserControl As UserControl

and change the constructor of the PageCollection as well:

Public Sub New(parent As UserControl)
 _parentUserControl = parent
End Sub

This will store the control that the class is going to be used with, thus

exposing its Control collection. Now, change the Add method:

Public Function Add(ByVal Item As Panel) As Integer
 _parentUserControl.Controls.Add(Item)
 Return List.Add(Item)
End Function

That will add the panel to the UserControl. Finally, you need to

change the constructor of the PageList class:

Public Sub New()
 MyBase.New()
 'This call is required by the Windows Form Designer.
 InitializeComponent()
 SetStyle(ControlStyles.AllPaintingInWmPaint, True)
 SetStyle(ControlStyles.DoubleBuffer, True)
 _pagecollection = New PageCollection(Me) '<-- I added the [b]Me[/b] parameter here, 
 'so the current UserControl will be passed to the PageCollection.
End Sub

  • *Experts*
Posted

A CollectionBase based class simply implements ICollection, IList, and

IEnumerable so that you can add objects to them and enumerate

them. The idea of typed collections is that you can make the 'Add'

function, etc. accept a type of object other than 'Object'. In the case of

Panel (which is a sub-class of Control), a typed-collection already

exists (System.Windows.Forms.ControlCollection). The Control collection

of the UserControl uses this type of collection and so will indeed work

in your case.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...