How do I get Graphic and Font objects from within a derived CellType

Posted by: j2associates on 8 September 2017, 1:27 pm EST

  • Posted 8 September 2017, 1:27 pm EST

    Hello all,


    I have overridden the ToString property of a derived CellType to display certain properties. I need to use the graphics MeasureString method. How do I get Graphics and Font objects for a derived CellType? Thanks in advance for any ideas and/or suggestions!

  • Replied 8 September 2017, 1:27 pm EST

    Thanks for responding Scott! Basically, I am just popping a message box with selected information displayed in it. MyCellType.ToString pops the message box.
  • Replied 8 September 2017, 1:27 pm EST

    Hello,


    The font object is not part of the CellType object. It is passed in from the StyleModel. The Graphics object is the same as the graphics object of the Spread.


    FpSpread1.CreateGraphics

  • Replied 8 September 2017, 1:27 pm EST

    Here is the code I am using. It seems to work but I am not sure that this is the best approach. Is there a better way?


        font = m_ParentSheet.DefaultStyle.Font
        If font Is Nothing Then font = m_ParentSpread.Font
        If font Is Nothing Then font = m_ParentSpread.FindForm.Font

  • Replied 8 September 2017, 1:27 pm EST

    Hello,


    Here is the corrected code to determine the font for a cell.


    Dim f As Font = FpSpread1.Sheets(0).GetStyleInfo(3, 3).Font


    If f Is Nothing Then f = FpSpread1.Font


    If f Is Nothing Then f = FpSpread1.Parent.Font

  • Replied 8 September 2017, 1:27 pm EST

    Hello,


    When do you need this information? The Spread passes the Graphics object and the Appearance object into most overrided functions. The Appearance object woudl have the Font being used.

  • Replied 8 September 2017, 1:27 pm EST

    Thanks Scott!
Need extra support?

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

Learn More

Forum Channels