窗体内隔行颜色.txt

来自「VB datagrid数据窗体隔行显示不同颜色,颜色可由用户自定义」· 文本 代码 · 共 46 行

TXT
46
字号
    '设置窗体内数据隔行显示颜色不同
Sub SetGridColor(GRID As Control, row_col As Boolean, color1 As Long, color2 As Long)
Dim i As Integer
Dim j As Integer
Dim K As Long
GRID.Redraw = False
With GRID
If row_col Then   '行间隔颜色
   For i = .FixedRows To .Rows - 1
        If K = color2 Then
           K = color1
        Else
           K = color2
        End If
           For j = .FixedCols To .Cols - 1
                .Col = j
                .Row = i
               .CellBackColor = K
           Next
        .RowHeight(i) = 280
    Next
   .Redraw = True
else
    For i = .FixedCols To .Cols - 1   '列间隔颜色
         If K = color2 Then
            K = color1 
         Else
            K = color2
         End If
     
        For j = .FixedRows To .Rows - 1
          .Col = i
          .Row = j
         .CellBackColor = K
        Next
    Next
   .Redraw = True
End If
End With
End Sub



'调用
   Call SetGridColor(grid1, True, &HD0FFE0, &HDFFFFF)  '行间隔色不同
   Call SetGridColor(grid1, flase, &HD0FFE0, &HDFFFFF)  '列间隔色不同

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?