Moin, ich habe gerade angefangen an einem ListView Control zu arbeiten und wollte dort gerne
den Hintergrund wo die ColumnHeader drauf sind bearbeiten, ich habe schon mal geschaut aber
leider nichts weiter dazu gefunden.
Siehe Bild
Mein Source Code:
Spoiler anzeigen
Lg Steve
den Hintergrund wo die ColumnHeader drauf sind bearbeiten, ich habe schon mal geschaut aber
leider nichts weiter dazu gefunden.
Siehe Bild
Mein Source Code:
VB.NET-Quellcode
- Class XListView
- Inherits ListView
- Sub New()
- GridLines = False
- FullRowSelect = True
- HeaderStyle = ColumnHeaderStyle.Nonclickable
- View = View.Details
- OwnerDraw = True
- ResizeRedraw = True
- Font = New Font("Arial", 8.25F, FontStyle.Regular)
- Size = New Size(300, 200)
- BorderStyle = BorderStyle.None
- BackColor = Color.FromArgb(245, 245, 245)
- SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.OptimizedDoubleBuffer, True)
- End Sub
- Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawListViewItemEventArgs)
- Me.Invalidate()
- MyBase.OnDrawItem(e)
- End Sub
- Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
- If Me.SelectedItems.Count = 1 Then
- Dim Item As ListViewItem = Me.SelectedItems(0)
- Select Case Item.Checked
- Case True
- Item.Checked = False
- Case Else
- Item.Checked = True
- End Select
- End If
- MyBase.OnClick(e)
- End Sub
- Protected Overrides Sub OnDrawColumnHeader(ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs)
- Me.SuspendLayout()
- Dim G As Graphics = e.Graphics
- Dim Rect As New Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height - 3)
- G.FillRectangle(New SolidBrush(Color.Black), Rect)
- G.DrawRectangle(Pens.Gray, Rect)
- Dim TextSizeF As SizeF = G.MeasureString(e.Header.Text, e.Font)
- Dim TextSize As Size = New Size(CInt(TextSizeF.Width), CInt(TextSizeF.Width))
- Dim TextLeft As Integer = CInt((e.Bounds.Width / 2) - (TextSizeF.Width / 2)) + e.Bounds.Left
- Dim TextTop As Integer = CInt((e.Bounds.Height / 2) - (TextSizeF.Height / 2)) + e.Bounds.Top
- G.DrawString(e.Header.Text, e.Font, New SolidBrush(Color.White), New Point(TextLeft, TextTop))
- Me.ResumeLayout()
- MyBase.OnDrawColumnHeader(e)
- End Sub
- Protected Overrides Sub OnDrawSubItem(ByVal e As System.Windows.Forms.DrawListViewSubItemEventArgs)
- Me.SuspendLayout()
- Dim G As Graphics = e.Graphics
- Dim TextSizeF As SizeF = G.MeasureString(e.SubItem.Text, e.SubItem.Font)
- Dim TextSize As Size = New Size(CInt(TextSizeF.Width), CInt(TextSizeF.Width))
- Dim TextLeft As Integer = CInt((e.Bounds.Width / 2) - (TextSizeF.Width / 2)) + e.Bounds.Left
- Dim TextTop As Integer = CInt((e.Bounds.Height / 2) - (TextSizeF.Height / 2)) + e.Bounds.Top
- Dim Rect As New Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height)
- G.FillRectangle(Brushes.DarkGray, e.Bounds)
- G.DrawRectangle(Pens.Gray, Rect)
- If Me.SelectedIndices.IndexOf(e.ItemIndex) > -1 Then
- Dim HighlightBaseColor As Color = e.Item.BackColor
- Dim HighlightColor As Color = Color.FromArgb(255, HighlightBaseColor)
- Dim ItemFillRectangle As New Rectangle(e.SubItem.Bounds.Left, e.SubItem.Bounds.Top, e.SubItem.Bounds.Width, e.SubItem.Bounds.Height)
- G.FillRectangle(New SolidBrush(HighlightColor), ItemFillRectangle)
- End If
- If Me.SelectedIndices.IndexOf(e.ItemIndex) > -1 Then
- G.DrawString(e.SubItem.Text, e.SubItem.Font, New SolidBrush(e.Item.ForeColor), New Point(TextLeft, TextTop))
- Else
- G.DrawString(e.SubItem.Text, e.SubItem.Font, New SolidBrush(e.Item.BackColor), New Point(TextLeft, TextTop))
- End If
- Me.ResumeLayout()
- MyBase.OnDrawSubItem(e)
- End Sub
- Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
- 'Dim B As New Bitmap(Width, Height)
- 'Dim G As Graphics = Graphics.FromImage(B)
- 'G.Clear(Parent.BackColor)
- 'G.Dispose() : B.Dispose()
- End Sub
- End Class
Lg Steve