Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/vb6/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb6 如何正确计算桌子的高度_Vb6_Msflexgrid - Fatal编程技术网

Vb6 如何正确计算桌子的高度

Vb6 如何正确计算桌子的高度,vb6,msflexgrid,Vb6,Msflexgrid,如何在VB6中计算flexgrid表格的高度,使其仅包含填充行数 目前 myFlexGrid.Height = (myFlexGrid.CellHeight * myFlexGrid.Rows) ' paraphrased from code 每行大约短3像素。加上这个神奇的数字有点老土,我想不必求助于它就可以做到这一点 更新: 要使事情复杂化,它还需要处理多行单元格。您需要继续 Me.MSFlexGrid1.Height = (Me.MSFlexGrid1.CellHeight) * (Me

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

目前

myFlexGrid.Height = (myFlexGrid.CellHeight * myFlexGrid.Rows) ' paraphrased from code
每行大约短3像素。加上这个神奇的数字有点老土,我想不必求助于它就可以做到这一点

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

您需要继续

Me.MSFlexGrid1.Height = (Me.MSFlexGrid1.CellHeight) * (Me.MSFlexGrid1.Rows + _
Me.MSFlexGrid1.FixedRows) + 30
30是为了使它长两个像素,以显示围绕flexgrid运行的黑色边框

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

您需要继续

Me.MSFlexGrid1.Height = (Me.MSFlexGrid1.CellHeight) * (Me.MSFlexGrid1.Rows + _
Me.MSFlexGrid1.FixedRows) + 30
30是为了使它长两个像素,以显示围绕flexgrid运行的黑色边框


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

RS Coneley即将关闭,但以下是说明所有DPI设置的正确方法:

Me.MSFlexGrid1.Height = Me.MSFlexGrid1.CellHeight _
                      * (Me.MSFlexGrid1.Rows + Me.MSFlexGrid1.FixedRows) _
                      + (Screen.TwipsPerPixelY * 2)

RS Coneley很接近,但以下是说明所有DPI设置的正确方法:

Me.MSFlexGrid1.Height = Me.MSFlexGrid1.CellHeight _
                      * (Me.MSFlexGrid1.Rows + Me.MSFlexGrid1.FixedRows) _
                      + (Screen.TwipsPerPixelY * 2)

这是我想出的最后一个代码

    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的值,但您应该能够自己声明:-)


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

这是我最后想到的代码

    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的值,但您应该能够自己声明:-)


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

实际上,从我所能找到的情况来看,30是不正确的:如果用户在120dpi模式下运行,那么12个twips等于1个像素。但我正试图避免添加半任意数。我还发现它需要处理多行单元格。除非控件明确支持autoheight函数或公开每个UI元素的高度值,否则无法避免使用幻数。这是因为控件被设计为黑匣子。看起来您的逻辑将变得复杂,我建议将flexgrid包装在一个控制类中,并在其中添加autoheight函数,以便您的主要例程中的代码保持干净。实际上,从我所能找到的情况来看,30是不正确的:如果用户在120dpi模式下运行,那么12 twips等于1像素。但我正试图避免添加半任意数。我还发现它需要处理多行单元格。除非控件明确支持autoheight函数或公开每个UI元素的高度值,否则无法避免使用幻数。这是因为控件被设计为黑匣子。看起来您的逻辑将变得复杂,我建议将flexgrid包装在一个控制类中,并在其中添加autoheight函数,以便主例程中的代码保持干净。