Header renderer row height

Posted by: kingmanb on 8 September 2017, 6:20 am EST

  • Posted 8 September 2017, 6:20 am EST

    How does fpspread calculate the preferred row height in the sheat header(s)?
    In this example the sheet rows loop through the GetPreferredSize function and the header rows do not.
    GetPreferredSize
    Imports FarPoint.Win.Spread
    Imports FarPoint.Win.Spread.CellType
    Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim h As New hr
    FpSpread1.Sheets(0).ColumnHeader.Cells(0, 0, 0, 2).Renderer = h
    FpSpread1.Sheets(0).Cells(0, 2, 0, 4).Renderer = h
    FpSpread1.Sheets(0).ColumnHeader.Cells(0, 3).Text = "Testing" & vbCrLf & "123"
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Debug.Print("Column Header preferred Height" & FpSpread1.Sheets(0).ColumnHeader.Rows(0).GetPreferredHeight.ToString)
    Debug.Print("Spreadsheet preferred Height" & FpSpread1.Sheets(0).Rows(0).GetPreferredHeight.ToString)
    End Sub
    End Class
    Public Class hr
    Inherits FarPoint.Win.Spread.CellType.ColumnHeaderRenderer
    Implements CellType.IRenderer
    Public Overrides Sub PaintCell(g As Graphics, r As Rectangle, appearance As Appearance, value As Object, isSelected As Boolean, isLocked As Boolean, zoomFactor As Single) Implements IRenderer.PaintCell

    End Sub
    Public Overloads Function GetPreferredSize(g As Graphics, size As Size, appearance As Appearance, value As Object, zoomFactor As Single) As Size Implements IRenderer.GetPreferredSize
    Debug.Print("Checking")
    Return New Size(50, 50)
    End Function
    End Class
  • Replied 8 September 2017, 6:20 am EST

    Sorry,
    I should have been more clear. . . I have placed in the header a custom cell type/renderer that won't return its preferred height by normal text measuring. I have placed the complex measuring code in the
    "Public Overloads Function GetPreferredSize"
    area of the renderer. The code is looped through (as shown in my example) during the:
    FpSpread1.Sheets(0).Rows(0).GetPreferredHeight.
    but not during the:
    FpSpread1.Sheets(0).ColumnHeader().Rows(0).GetPreferredHeight
    I am wondering where is the measuring taking place?
  • Replied 8 September 2017, 6:20 am EST

    Hello,

    Please use this code to set height of row header:-

    FpSpread1.ActiveSheet.ColumnHeader().Rows(0).GetPreferredHeight


    Hope it helps.

    Thanks,
    Reeva
  • Replied 8 September 2017, 6:20 am EST

    Hi,

    I think I see what is happening, and it looks like a problem inside the built-in column header renderers in Spread.

    The issue is, the logic of GetPreferredColumnHeaderRowHeight (which is called by Row.GetPreferredSize in this case) does not actually call into the cell renderer's GetPreferredSize implementation. Instead, the logic checks whether the renderer is FpButton (which is a base class for all built-in column header renderers), and then directly calls into FpButton.GetPreferredSize (bypassing the cell renderer completely), which is not correct.

    To get around this problem, you can implement your custom renderer to wrap around the built-in renderer that you want to subclass, instead of inheriting directly from the class, and implement the interface methods for column header renderer in your class to call the wrapped renderer instance. I have attached a small sample to illustrate this. Sorry for the inconvenience!

    Regards,
    -Sean
    2015/11/Form11.zip
  • Replied 8 September 2017, 6:20 am EST

    Hello,

    I am not clear about your issue. Could you please elaborate more on the same so that we can investigate this issue further.

    Please revert back and elaborate. We will look into this issue further.

    Thanks,
    Reeva
  • Replied 26 September 2018, 10:03 am EST

    Hi Sean,
    I finally got around to following your advice and wrapping the header renderer. There is a problem, though.
    Whereas the IRenderer.PaintCell sub includes the value object which is the actual value of the header cell, the IRenderer.GetPreferredSize value object is as string, presumably from the cell value tostring function. Since I include formatting (and other) information in the value object, I can't properly get the preferred size.
    -Kingman
  • Replied 3 January 2019, 2:57 am EST

    Folks,
    This problem has not been fixed in version 12. After Implementing IRenderer
     Public Function IRenderer_GetPreferredSize(g As Graphics,
    size As Size,
    appearance As FarPoint.Win.Spread.Appearance,
    value As Object,
    zoomFactor As Single) As Size Implements IRenderer.GetPreferredSize

    The value object above is showing up as a string, not the actual value of a cell. I would seem that the value should be the value.
    -Kingman
  • Replied 11 February 2020, 7:35 am EST

    Another problem with IRenderer.GetPreferredSize is that the zoomfactor provided in:
     Public Function _GetPreferredSize(g As Graphics, size As Size, appearance As Spread.Appearance, value As Object, zoomFactor As Single) As Size Implements IRenderer.GetPreferredSize

    is always 1.
    Since fonts do not scale exactly when zoomed , this leads to incorrect results. The only way to properly calculate the proper preferred size is to:
    1. Find out the actual zoomFactor.

    2. Scale the font based on the zoomFactor
    3. Measure the text based on the zoomed font to a size
    4. reduce that size by 1/zoomFactor
    It would be helpful if the zoomFactor provided was the actual zoomFactor of the sheet.
    -Kingman
  • Replied 17 February 2020, 4:48 pm EST

    Hi Kingman,

    Apologies for the delay but it looks like an intended behavior. Currently, it always pass "1" to CellType.GetPreferredSize method to measure the cell size, then when Spread go to paint it will multiply the size with zoom factor. Hence, it is a limitation.

    Apologies for the inconvenience caused.

    ~Ruchir
  • Replied 18 February 2020, 4:06 am EST

    Hi Ruchir,
    This is probably not true since the spread default behavior works and correctly measures the proper preferred size. This cannot be done without knowing the actual size of the font being painted and the actual zoomfactor of the sheet. There is no guarantee that the font on a sheet that has been zoomed 200% is twice the size of the font painted on the sheet when it is Zoomed 100%.
    Please check with the developers.
    -Kingman
  • Replied 18 February 2020, 11:26 pm EST

    Hello Kingman,

    I have forwarded your concern to the developer [SPNET-3356] and will update you once we receive some information.

    Thanks,
    Ruchir
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels