Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何在VB.net中为DataGridView提供通用样式_Css_Vb.net_Datagridview_Formatting - Fatal编程技术网

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

Css 如何在VB.net中为DataGridView提供通用样式,css,vb.net,datagridview,formatting,Css,Vb.net,Datagridview,Formatting,如何创建一个类或其他东西,使我的项目中的所有DataGridView具有相同的格式,即AlternativeRowColor、ForColor、BackColor和其他属性。目前,我必须去设置每个控件属性,当用户请求更改和网格属性时,它会很糟糕,因为我必须在所有DataGridView中更改 Public Class FrmArticle Private Sub GridFormatting(ByVal DGV As DataGridView) DGV.ForeColor

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

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


我想补充一点,您可以将其作为辅助函数添加到另一个类中(作为共享方法,或者在模块中)。如果需要,甚至可以将其作为扩展方法;)在何处添加此GridFormatting函数?我们可能会在帮助程序类中添加帮助程序,或者直接将一个新的bee添加到VB.net中,您能否解释在何处添加帮助程序类以及如何将其继承到窗体?使用您的类添加或设置单独的模块并调用它
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