1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| Public Class MyDGVColumn
Inherits DataGridViewTextBoxColumn
Public Sub New()
MyBase.HeaderCell = New MyHeadCell
End Sub
End Class
Public Class MyHeadCell
Inherits DataGridViewColumnHeaderCell
Public Sub New()
End Sub
Protected Overrides Sub Paint(ByVal graphics As System.Drawing.Graphics, ByVal clipBounds As System.Drawing.Rectangle, _
ByVal cellBounds As System.Drawing.Rectangle, ByVal rowIndex As Integer, ByVal dataGridViewElementState As System.Windows.Forms.DataGridViewElementStates, _
ByVal value As Object, ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As System.Windows.Forms.DataGridViewCellStyle, _
ByVal advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, ByVal paintParts As System.Windows.Forms.DataGridViewPaintParts)
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)
Dim Monthes() As String = {"Jan", "Feb", "Mar"}
For A As Int32 = 0 To 5
Dim Rect As Rectangle = cellBounds
Rect.X += 1
Rect.Y += 1
Rect.Width = Rect.Width * 2 - 2
Rect.Height = Rect.Height / 2 - 2
graphics.FillRectangle(Brushes.Salmon, Rect)
Dim Format As New StringFormat()
Format.Alignment = StringAlignment.Center
Format.LineAlignment = StringAlignment.Center
graphics.DrawString(Monthes(A / 2), cellStyle.Font, Brushes.Purple, Rect, Format)
A += 1
Next
End Sub
End Class |
Partager