0

如何计算 VB6 中 flexgrid 表的高度,使其仅包含填充的行数。

目前

myFlexGrid.Height = (myFlexGrid.CellHeight * myFlexGrid.Rows) ' paraphrased from code

每行短约 3 个像素。添加幻数有点骇人听闻,并且希望无需求助即可完成此操作。

更新: 为了使事情复杂化,它还需要处理多行单元格。

4

3 回答 3

2

RS Coneley 很接近,但这里是解释所有 DPI 设置的正确方法:

Me.MSFlexGrid1.Height = Me.MSFlexGrid1.CellHeight _
                      * (Me.MSFlexGrid1.Rows + Me.MSFlexGrid1.FixedRows) _
                      + (Screen.TwipsPerPixelY * 2)
于 2009-04-22T14:14:16.077 回答
1

你需要去

Me.MSFlexGrid1.Height = (Me.MSFlexGrid1.CellHeight) * (Me.MSFlexGrid1.Rows + _
Me.MSFlexGrid1.FixedRows) + 30

30 是让它长两个像素,以显示围绕 flexgrid 运行的黑色边框。

禁用垂直滚动条也有帮助。

于 2009-04-22T12:29:08.107 回答
0

这是我想出的最终代码

    For i = 0 To fgrComments.Rows - 1
        'Set MSFlexGrid to appropriate Cell
        myFlexGrid.Row = i

        'Set textbox to match the selected cell
        txtSizer.Width = myFlexGrid.ColWidth(2)
        txtSizer.Font = myFlexGrid.Font
        txtSizer.Text = myFlexGrid.Text

        'Call API to determine how many lines of text are in text box
        lLinesOfText = SendMessage(txtSizer.hwnd, EM_GETLINECOUNT, 0&, 0&)

        ' Update the running values
        lTotalNumberOfRows = lTotalNumberOfRows + lLinesOfText
        lCurrentHeight = lCurrentHeight + myFlexGrid.CellHeight
    Next i

    ' resize the grid
    Dim iSpacers As Integer
    iSpacers = Screen.TwipsPerPixelY * lTotalNumberOfRows
    myFlexGrid.Height = lCurrentHeight + iSpacers

您将需要声明 SendMessage(请参阅此处了解如何)和 EM_GETLINECOUNT 的值,但您应该能够自己执行此操作:-)

它不会删除神奇的数字,但它确实使它们合理化,这对我来说已经足够接近了。

于 2009-04-23T09:01:46.910 回答