datagridcoloredtextboxcolumn.vb
来自「数据网格数据Custom_Data_Grid_src_demo」· VB 代码 · 共 96 行
VB
96 行
Option Strict On
Option Explicit On
Option Compare Text
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Namespace CustomControls
Public Class DataGridColoredTextBoxColumn
Inherits DataGridTextBoxColumn
Private m_backColor As Color
Private m_foreColor As Color
Public Property BackColor() As Color
Get
If m_backColor.IsEmpty Then
m_backColor = DataGridTableStyle.BackColor
End If
Return m_backColor
End Get
Set(ByVal Value As Color)
m_backColor = Value
End Set
End Property
Public Property ForeColor() As Color
Get
If m_foreColor.IsEmpty Then
m_foreColor = DataGridTableStyle.ForeColor
End If
Return m_foreColor
End Get
Set(ByVal Value As Color)
m_foreColor = Value
End Set
End Property
Private Function GetText(ByVal Value As Object) As String
If TypeOf (Value) Is System.DBNull Then
Return NullText
ElseIf Value Is Nothing Then
Return ""
Else
Return Value.ToString
End If
End Function
Protected Overloads Overrides Sub Paint( _
ByVal g As System.Drawing.Graphics, _
ByVal bounds As System.Drawing.Rectangle, _
ByVal source As System.Windows.Forms.CurrencyManager, _
ByVal rowNum As Integer)
MyClass.Paint(g, bounds, source, rowNum, False)
End Sub
Protected Overloads Overrides Sub Paint( _
ByVal g As System.Drawing.Graphics, _
ByVal bounds As System.Drawing.Rectangle, _
ByVal source As System.Windows.Forms.CurrencyManager, _
ByVal rowNum As Integer, ByVal alignToRight As Boolean)
Dim backBrush As Brush
Dim foreBrush As Brush
backBrush = New SolidBrush(BackColor)
foreBrush = New SolidBrush(ForeColor)
MyClass.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)
End Sub
Protected Overloads Overrides Sub Paint( _
ByVal g As System.Drawing.Graphics, _
ByVal bounds As System.Drawing.Rectangle, _
ByVal source As System.Windows.Forms.CurrencyManager, _
ByVal rowNum As Integer, _
ByVal backBrush As System.Drawing.Brush, _
ByVal foreBrush As System.Drawing.Brush, _
ByVal alignToRight As Boolean)
Dim text As String
text = GetText(GetColumnValueAtRow(source, rowNum))
backBrush = New SolidBrush(BackColor)
foreBrush = New SolidBrush(ForeColor)
MyBase.PaintText(g, bounds, text, backBrush, foreBrush, alignToRight)
End Sub
Public Overrides Property [ReadOnly]() As Boolean
Get
Return True
End Get
Set(ByVal Value As Boolean)
Throw New NotSupportedException("ReadOnly property is not changable!")
End Set
End Property
End Class
End Namespace
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?