如何在VB.net中为DataGridView提供通用样式

时间:2013-12-12 03:25:08

标签: css vb.net datagridview formatting

如何创建一个类或其他东西来使我的项目中的所有DataGridView具有相同的格式i:e AlternativeRowColor,ForColor,BackColor和Other属性。目前我必须去每个控件属性来设置,当用户请求更改和Grid的属性时它很糟糕,因为我必须在所有DataGridView中进行更改。

1 个答案:

答案 0 :(得分:2)

Public Class FrmArticle

       Private Sub GridFormatting(ByVal DGV As DataGridView)
    DGV.ForeColor = Color.Black
    DGV.BackgroundColor = Color.AliceBlue
    DGV.AlternatingRowsDefaultCellStyle.BackColor = Color.Brown
    DGV.AlternatingRowsDefaultCellStyle.ForeColor = Color.DodgerBlue
    DGV.ColumnHeadersDefaultCellStyle.ForeColor = Color.CadetBlue
    DGV.ColumnHeadersDefaultCellStyle.BackColor = Color.DarkGoldenrod
    DGV.EnableHeadersVisualStyles = False
         End Sub

        Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                GridFormatting(DataGridView1)
        End Sub
    End Class

Module GridFormat
    Public Sub GridFormatting(ByVal DGV As DataGridView)
    DGV.ForeColor = Color.Black
    DGV.BackgroundColor = Color.AliceBlue
    DGV.AlternatingRowsDefaultCellStyle.BackColor = Color.Brown
    DGV.AlternatingRowsDefaultCellStyle.ForeColor = Color.DodgerBlue
    DGV.ColumnHeadersDefaultCellStyle.ForeColor = Color.CadetBlue
    DGV.ColumnHeadersDefaultCellStyle.BackColor = Color.DarkGoldenrod
    DGV.EnableHeadersVisualStyles = False
    End Sub
End Module


Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
               GridFormatting(DataGridView1)
End Sub