Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sorry, when I search in google etc. i can't find what i needed

I can't keep a collection with items, when I exit the designer or debug, my Collection get blank..

Here is my code:

ExplorerBarItemData.vb
VB
Public Class ExplorerBarItemData
#Region "Fields"
    Private fText As String = "Text"
    Private fIcon As Image
    Private fLink As String
#End Region
#Region "Properties"
    Public Property Text As String
        Get
            Return fText
        End Get
        Set(ByVal value As String)
            fText = value
        End Set
    End Property
    Public Property Icon As Image
        Get
            Return fIcon
        End Get
        Set(ByVal value As Image)
            fIcon = value
        End Set
    End Property
    Public Property Link As String
        Get
            Return fLink
        End Get
        Set(ByVal value As String)
            fLink = value
        End Set
    End Property
#End Region
#Region "Creator"
    Public Sub New()

    End Sub
    Public Sub New(ByVal Text As String, ByVal Icon As Image, ByVal Link As String)
        Me.Text = Text
        Me.Icon = Icon
        Me.Link = Link
    End Sub
    Public Sub New(ByVal Data As ExplorerBarItemData)
        Me.Text = Data.Text
        Me.Icon = Data.Icon
    End Sub
#End Region
End Class


ExplorerBarItem.vb

VB
Imports System.ComponentModel
Public Class ExplorerBarItem
#Region "Fields"
    Private fData As ExplorerBarItemData
#End Region
#Region "Properties"
    <Browsable(False)> _
    Public Property Data As ExplorerBarItemData
        Get
            Return fData
        End Get
        Set(ByVal value As ExplorerBarItemData)
            fData = value
        End Set
    End Property
    Public Property Text As String
        Get
            Return Data.Text
        End Get
        Set(ByVal value As String)
            Data.Text = value
        End Set
    End Property
    Public Property Link As String
        Get
            Return Data.Link
        End Get
        Set(ByVal value As String)
            Data.Link = value
        End Set
    End Property
    Public Property Icon As Image
        Get
            Return Data.Icon
        End Get
        Set(ByVal value As Image)
            Data.Icon = value
        End Set
    End Property
#End Region
    Public Sub New()
        If Me.Data Is Nothing Then Me.Data = New ExplorerBarItemData
    End Sub
    Friend Sub Render(ByVal G As Graphics, ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal MyFont As Font)
        If Data Is Nothing Then Exit Sub

        G.FillRectangle(Brushes.White, X, Y, Width, Height)

        Dim ImageRectangle As New Rectangle(0, Y, 24, 24)
        Dim TextRectangle As New Rectangle(24, Y, Width - 25, 24)
        Dim SF As New StringFormat
        SF.Alignment = StringAlignment.Near
        SF.LineAlignment = StringAlignment.Center

        If Me.Data.Icon IsNot Nothing Then
            G.DrawImage(Me.Data.Icon, ImageRectangle)
        End If

        Dim Font As New Font(MyFont.FontFamily, MyFont.Size)
        Dim FontColor As Brush = Brushes.Black

        If String.IsNullOrWhiteSpace(Me.Data.Link) = False Then
            Font = New Font(MyFont.FontFamily, MyFont.Size, FontStyle.Underline)
            FontColor = Brushes.Blue
        Else
        End If

        G.DrawString(Me.Data.Text, Font, FontColor, TextRectangle, SF)
    End Sub
    Public Function Clone() As ExplorerBarItem
        Return CType(Me.MemberwiseClone, ExplorerBarItem)
    End Function
End Class


ExplorerBarItemCollection.vb

VB
Public Class ExplorerBarItemCollection
    Inherits List(Of ExplorerBarItem)

End Class


The Control:

VB
Public Class ExplorerBarItemGroup
    Inherits Control
#Region "Fields"
    Private fItems As New ExplorerBarItemCollection
#End Region
#Region "Properties"
    Public ReadOnly Property Items As ExplorerBarItemCollection
        Get
            Return fItems
        End Get
    End Property
#End Region
#Region "Methods"
 #End Region
#Region "Creator"
    Public Sub New()
        Me.DoubleBuffered = True

        Me.Height = Items.Count * 24
    End Sub
#End Region
#Region "Render"
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)

        For I As Integer = 0 To Items.Count - 1
            Items.Item(I).Render(e.Graphics, 0, I * 24, e.ClipRectangle.Width, 24, Me.Font)
        Next
    End Sub
#End Region
End Class
Posted

1 solution

You must add the following line to your Property :
VB
 <system.componentmodel.designerserializationvisibility(system.componentmodel.designerserializationvisibility.content)>
Public ReadOnly Property Items As ExplorerBarItemCollection
     Get
         Return fItems
     End Get
 End Property
 
Share this answer
 
Comments
Adrian Andrei 24-Jul-15 8:57am    
Thanks! It worked!
Ralf Meier 24-Jul-15 9:04am    
You are welcome ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900