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
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
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
Public Class ExplorerBarItemCollection
Inherits List(Of ExplorerBarItem)
End Class
The Control:
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