При этом в классе DataGridViewColorStateColumn есть динамический массив картинок Dim Bitmaps() As Bitmap
Как передать указатель на Dim Bitmaps() в создаваемый подкласс
и как потом с помощью этого указателя получить доступ к картинкам Dim Bitmaps() находящимся в "материнском" классе.
Логический все понятно, но как записать не знаю подскажите
- Код: Выделить всё
Public Class DataGridViewColorStateColumn
Inherits DataGridViewColumn
Dim Bitmaps() As Bitmap
Public Sub UploadImage(ByVal Path As String)
End Sub
Public Sub New()
MyBase.New(New DataGridViewColorStateCell)
End Sub
Public Overrides Property CellTemplate() As DataGridViewCell
Get
Return MyBase.CellTemplate
End Get
Set(ByVal value As DataGridViewCell)
' Ensure that the cell used for the template is a CalendarCell.
If Not (value Is Nothing) AndAlso _
Not value.GetType().IsAssignableFrom(GetType(DataGridViewColorStateCell)) _
Then
Throw New InvalidCastException("Must be a DataGridViewColorStateCell")
End If
MyBase.CellTemplate = value
End Set
End Property
End Class
Public Class DataGridViewColorStateCell
Inherits DataGridViewTextBoxCell
Dim brushPercent As Brush
Public Sub New()
Me.Style.Format = "0"
End Sub
Public Overrides ReadOnly Property EditType() As System.Type
Get
Return Nothing
End Get
End Property
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
Dim adr As Point = MyBase.DataGridView.CurrentCellAddress
If adr.X = e.ColumnIndex And adr.Y = e.RowIndex Then
If e.Button = MouseButtons.Left Then
MyBase.DataGridView.CurrentCell.Value += 1
End If
If e.Button = MouseButtons.Right Then
MyBase.DataGridView.CurrentCell.Value -= 1
End If
End If
MyBase.OnMouseClick(e)
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 cellState 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)
Dim p As Double = 0
If value IsNot Nothing AndAlso _
Not IsDBNull(value) AndAlso _
IsNumeric(value) Then
p = value / 100
End If
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, DataGridViewPaintParts.Background Or DataGridViewPaintParts.Border Or DataGridViewPaintParts.ErrorIcon Or DataGridViewPaintParts.Focus Or DataGridViewPaintParts.SelectionBackground)
If p > 0 Then
Dim r As Drawing.Rectangle
r.X = cellBounds.X + 5
r.Y = cellBounds.Y + 5
r.Width = (cellBounds.Width - 10) * p
r.Height = cellBounds.Height - 10
If r.Width > 0 Then
If Me.brushPercent IsNot Nothing Then
Me.brushPercent.Dispose()
Me.brushPercent = Nothing
End If
Me.brushPercent = New Drawing.Drawing2D.LinearGradientBrush(r, Drawing.Color.White, Drawing.Color.DarkBlue, Drawing.Drawing2D.LinearGradientMode.Vertical)
graphics.FillRectangle(Me.brushPercent, r)
graphics.DrawRectangle(Drawing.Pens.DimGray, r)
End If
End If
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, DataGridViewPaintParts.None Or DataGridViewPaintParts.ContentForeground)
End Sub
End Class