我想设定MSFlexGrid1控件的每一行的色彩与MSFlexGrid1控件背景色都不一样?怎么写.
我的效果是想达到,MSFlexGrid1每一行的色彩一排一排的变.直到最后一排.

解决方案 »

  1.   

    Public Sub SetMSHFlexGridColColor(ByRef grdSet As MSHFlexGrid, ByVal intCol As Integer, _
        Optional ByVal lngFColor As Long = vbBlack, Optional ByVal lngBColor As Long = vbWhite, _
        Optional ByVal lngBackColor As Long = vbWhite)
        Dim i As Long
        
        With grdSet
            .BackColor = lngBackColor
            For i = 1 To .Rows - 1
                .Row = i
                .Col = intCol
                .CellForeColor = lngFColor
                .CellBackColor = lngBColor
            Next i
        End With
    End Sub'ÉèÖÃMSHFlexGridÿÐеÄÑÕÉ«
    Public Sub SetMSHFlexGridRowColor(ByRef grdSet As MSHFlexGrid, ByRef lngBColor As Long)
        Dim j As Long
        Dim i As Long
        Dim strObjectName As String
        
        strObjectName = TypeName(grdSet)
        If StrConv(Trim(strObjectName), vbUpperCase) <> UCase("MSHFlexGrid") Then
            Exit Sub
        End If
        grdSet.FillStyle = flexFillRepeat
        For i = 1 To grdSet.Rows - 1
            grdSet.Row = i
            If i Mod 2 = 0 Then
                grdSet.Col = 1
                grdSet.ColSel = grdSet.Cols - 1
                grdSet.CellBackColor = lngBColor
            End If
        Next i
        grdSet.FillStyle = 0
        grdSet.Row = 0
        grdSet.Col = 0
    End Sub
      

  2.   

    ’设置某列
    Public Sub SetMSHFlexGridColColor(ByRef grdSet As MSHFlexGrid, ByVal intCol As Integer, _
        Optional ByVal lngFColor As Long = vbBlack, Optional ByVal lngBColor As Long = vbWhite, _
        Optional ByVal lngBackColor As Long = vbWhite)
        Dim i As Long
        
        With grdSet
            .BackColor = lngBackColor
            For i = 1 To .Rows - 1
                .Row = i
                .Col = intCol
                .CellForeColor = lngFColor
                .CellBackColor = lngBColor
            Next i
        End With
    End Sub'MSHFlexGrid
    Public Sub SetMSHFlexGridRowColor(ByRef grdSet As MSHFlexGrid, ByRef lngBColor As Long)
        Dim j As Long
        Dim i As Long
        Dim strObjectName As String
        
        strObjectName = TypeName(grdSet)
        If StrConv(Trim(strObjectName), vbUpperCase) <> UCase("MSHFlexGrid") Then
            Exit Sub
        End If
        grdSet.FillStyle = flexFillRepeat
        For i = 1 To grdSet.Rows - 1
            grdSet.Row = i
            If i Mod 2 = 0 Then
                grdSet.Col = 1
                grdSet.ColSel = grdSet.Cols - 1
                grdSet.CellBackColor = lngBColor
            End If
        Next i
        grdSet.FillStyle = 0
        grdSet.Row = 0
        grdSet.Col = 0
    End Sub