Hallo liebe Community,
ich habe dieses Control im i-net gefunden:
Control
Jedoch weiß ich nicht wie ich ein Item dazu adde.
Bitte um Hilfe.
Danke im Vorraus.
ich habe dieses Control im i-net gefunden:
VB.NET-Quellcode
- Public Class ListControl : Inherits ListBox
- Public Sub New()
- Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
- Me.ItemHeight = 100
- End Sub
- Dim _FontSubText As Font = Me.Font
- Public Property FontSubText() As Font
- Get
- Return _FontSubText
- End Get
- Set(ByVal value As Font)
- _FontSubText = value
- End Set
- End Property
- Dim _FontTopText As Font = Me.Font
- Public Property FontTopText() As Font
- Get
- Return _FontTopText
- End Get
- Set(ByVal value As Font)
- _FontTopText = value
- End Set
- End Property
- Dim _SelectedBackColor As Color = Color.CornflowerBlue
- Public Property SelectedBackColor() As Color
- Get
- Return _SelectedBackColor
- End Get
- Set(ByVal value As Color)
- _SelectedBackColor = value
- End Set
- End Property
- Dim _BorderColor As Color = Color.Gray
- Public Property BorderColor() As Color
- Get
- Return _BorderColor
- End Get
- Set(ByVal value As Color)
- _BorderColor = value
- End Set
- End Property
- Dim _SelectedBorderColor As Color = Color.DarkGray
- Public Property SelectedBorderColor() As Color
- Get
- Return _SelectedBorderColor
- End Get
- Set(ByVal value As Color)
- _SelectedBorderColor = value
- End Set
- End Property
- Dim _TopTextForeColor As Color = Color.Black
- Public Property TopTextForeColor() As Color
- Get
- Return _TopTextForeColor
- End Get
- Set(ByVal value As Color)
- _TopTextForeColor = value
- End Set
- End Property
- Dim _SubTextForeColor As Color = Color.Gray
- Public Property SubTextForeColor() As Color
- Get
- Return _SubTextForeColor
- End Get
- Set(ByVal value As Color)
- _SubTextForeColor = value
- End Set
- End Property
- Private Sub ListControl_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Me.DrawItem
- If e.Index > -1 AndAlso e.Index < (Items.Count) Then
- Dim tmp As New ListControlItem(New Bitmap(1, 1), "a", "b", "c")
- If Me.Items(e.Index).GetType Is tmp.GetType Then
- Dim r As Rectangle = New Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 3, e.Bounds.Height - 2)
- tmp = CType(Me.Items(e.Index), ListControlItem)
- With e.Graphics
- If e.Index = Me.SelectedIndex Then
- .FillRectangle(New SolidBrush(SelectedBackColor), r)
- .DrawRectangle(New Pen(New SolidBrush(SelectedBorderColor)), r)
- Else
- .FillRectangle(New SolidBrush(Color.Transparent), r)
- .DrawRectangle(New Pen(New SolidBrush(BorderColor)), r)
- End If
- If tmp.Image IsNot Nothing Then .DrawImage(tmp.Image, r.X + 5, r.Y + 5, 45, 45) Else .DrawIcon(Drawing.SystemIcons.Error, r.X + 5, r.Y + 5)
- .DrawString(tmp.TopText, Me.FontTopText, New SolidBrush(TopTextForeColor), New Rectangle(r.X + 60, r.Y + 5, Me.Width - (r.X + 60), CInt(.MeasureString(tmp.TopText, Me.FontTopText).Height)))
- .DrawString(tmp.MainContent, Me.Font, New SolidBrush(Me.ForeColor), New Rectangle(r.X + 60, r.Y + 25, Me.Width - (r.X + 60), CInt(60 - .MeasureString(tmp.TopText, Me.FontTopText).Height - .MeasureString(tmp.SubText, Me.FontSubText).Height)))
- .DrawString(tmp.SubText, Me.FontSubText, New SolidBrush(SubTextForeColor), New Rectangle(r.X + 60, r.Y + Me.ItemHeight - 20, Me.Width - (r.X + 60), CInt(.MeasureString(tmp.SubText, Me.FontSubText).Height)))
- End With
- End If
- End If
- End Sub
- Private Sub ListControl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SelectedIndexChanged
- Me.Invalidate()
- End Sub
- End Class
- Public Class ListControlItem
- Public Sub New(ByVal _IMG As Bitmap, ByVal _TopText As String, ByVal _mainCont As String, ByVal _SubText As String)
- If Image IsNot Nothing Then Image = _IMG
- TopText = _TopText
- SubText = _SubText
- MainContent = _mainCont
- End Sub
- Public Image As Bitmap = New Bitmap(1, 1)
- Public TopText As String = ""
- Public MainContent As String = ""
- Public SubText As String = ""
- End Class
Jedoch weiß ich nicht wie ich ein Item dazu adde.
Bitte um Hilfe.
Danke im Vorraus.
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Gather“ ()