自定义控件之DataGridView(美化单元格的外观)

 

     dim  mLinearColor1  As  Color  =  Color.FromArgb( 248 250 251 )
    
dim  mLinearColor2  As  Color  =  Color.FromArgb( 196 207 224 )
    
dim  mGridColor  As  Color  =  Color.FromArgb( 120 147 191 )                   ' 网格线的颜色
     dim  mBorderColor  As  Color  =  Color.MediumBlue                                     ' 控件边框的颜色
     dim  mMouseInColor  As  Color  =  Color.Orange                                           ' 鼠标进入时控件的颜色
     dim  mHasFocusedColor  As  Color  =  Color.DarkCyan                               ' 控件的焦点框颜色 

Private   Sub MyDataGridView_CellPainting(ByVal sender As ObjectByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles Me.CellPainting
        
Dim StrFormat As New System.Drawing.StringFormat
        
Dim Rect As Rectangle = New Rectangle(e.CellBounds.X - 1, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height - 1)
        
Dim LinearGradientBrush As New Drawing2D.LinearGradientBrush(Rect, mLinearColor1, mLinearColor2, Drawing2D.LinearGradientMode.Vertical)

        
Try
            
If e.RowIndex = -1 Or e.ColumnIndex = -1 Then
                e.Graphics.FillRectangle(LinearGradientBrush, Rect)
                e.Graphics.DrawRectangle(
New Pen(GridColor), Rect)
                e.PaintContent(e.CellBounds)
                e.Handled 
= True
            
End If

        
Catch ex As Exception
        
Finally
            Rect 
= Nothing
            StrFormat.Dispose()
            
If LinearGradientBrush IsNot Nothing Then LinearGradientBrush.Dispose()
        
End Try
    
End Sub

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页