ばかりしている:MSHFlexGrid控件列宽自动调整

来源:百度文库 编辑:偶看新闻 时间:2024/05/04 16:55:16

MSHFlexGrid控件列宽自动调整

今天在单位里没事帮朋友做了个建议通讯录,呵呵,没什么技术含量,不过里面有个控件还是值得介绍的。那就是MSHFlexGrid控件。

我写了个能自动调整列宽的模块,在这里介绍给大家:

Public Sub AdjustColWidth(frmCur As Form, gridCur As Object, Optional bNullRow As Boolean = True, Optional dblIncWidth As Double = 0)
'--------------------------------------------------------------------
'功能:
      自动调整Grid各列列宽为最合适的宽度
'参数:
      [frmCur].........................................当前工作窗体
      [gridCur]........................................当前要调整的Grid
'--------------------------------------------------------------------
Dim i, j As Integer
Dim dblWidth As Double
    With gridCur
        For i = 0 To .Cols - 1
            dblWidth = 0
            If .ColWidth(i) <> 0 Then
                For j = 0 To .Rows - 1
                    If frmCur.TextWidth(.TextMatrix(j, i)) > dblWidth Then
                        dblWidth = frmCur.TextWidth(.TextMatrix(j, i))
                    End If
                Next
                .ColWidth(i) = dblWidth + dblIncWidth + 100
            End If
        Next
    End With
 
End Sub

把这段代码单独写到模块中,在在窗体中调用既可。还请大家多提点意见。