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

    <P>Hello all,</P>
    <P>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!</P>
  • 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

    <P>Hello,</P>
    <P>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.</P>
    <P>FpSpread1.CreateGraphics</P>
  • Replied 8 September 2017, 1:27 pm EST

    <P>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?</P>
    <P>    font = m_ParentSheet.DefaultStyle.Font<BR>    If font Is Nothing Then font = m_ParentSpread.Font<BR>    If font Is Nothing Then font = m_ParentSpread.FindForm.Font<BR></P>
  • Replied 8 September 2017, 1:27 pm EST

    <P>Hello,</P>
    <P>Here is the corrected code to determine the font for a cell.</P><FONT size=2>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> f </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> Font = FpSpread1.Sheets(0).GetStyleInfo(3, 3).Font</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>If</FONT></FONT><FONT size=2> f </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Is</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Nothing</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Then</FONT></FONT><FONT size=2> f = FpSpread1.Font</P>
    <P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>If</FONT></FONT><FONT size=2> f </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Is</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Nothing</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Then</FONT></FONT><FONT size=2> f = FpSpread1.Parent.Font</P></FONT>
  • Replied 8 September 2017, 1:27 pm EST

    <P>Hello,</P>
    <P>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.</P>
  • 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