CSDN博客

img yinweihong

Autoresize of columns in MSHFlexGrid with multiple bands

发表于2004/9/26 14:48:00  1020人阅读

Public Function FG_AutosizeCols(myGrid As MSHFlexGrid, _
                                Optional ByVal lFirstCol As Long = -1, _
                                Optional ByVal lLastCol As Long = -1, _
                                Optional bCheckFont As Boolean = False)
    Dim lCol As Long, lRow As Long, lCurCol As Long, lCurRow As Long
    Dim lCellWidth As Long, lColWidth As Long
    Dim bFontBold As Boolean
    Dim dFontSize As Double
    Dim sFontName As String
    If bCheckFont Then
        ' save the forms font settings
        bFontBold = Me.FontBold
        sFontName = Me.FontName
        dFontSize = Me.FontSize
    End If
    With myGrid
        .Redraw = False
        If bCheckFont Then
            lCurRow = .Row
            lCurCol = .Col
        End If
        If lFirstCol = -1 Then lFirstCol = 0
        ' Special for MSHFlexGrid with multiple bands
        If lLastCol = -1 Then
            lLastCol = 0
            For i = 0 To .Bands - 1
                lLastCol = lLastCol + .Cols(i)
            Next i
            lLastCol = lLastCol - 1
        End If
        For lCol = lFirstCol To lLastCol
            lColWidth = 0
            If bCheckFont Then .Col = lCol
            For lRow = 0 To .Rows - 1
                If bCheckFont Then
                    .Row = lRow
                    Me.FontBold = .CellFontBold
                    Me.FontName = .CellFontName
                    Me.FontSize = .CellFontSize
                End If
                lCellWidth = Me.TextWidth(.TextMatrix(lRow, lCol))
                If lCellWidth > lColWidth Then lColWidth = lCellWidth
            Next lRow
            .ColWidth(lCol) = lColWidth + Me.TextWidth("WW")
        Next lCol
        If bCheckFont Then
            .Row = lCurRow
            .Col = lCurCol
        End If
        .Redraw = True
    End With
    If bCheckFont Then
        ' restore the forms font settings
        Me.FontBold = bFontBold
        Me.FontName = sFontName
        Me.FontSize = dFontSize
    End If
End Function

阅读全文
0 0

相关文章推荐

img
取 消
img