5

In C# I would like to programmatically change the font metrics of a font that I load.

Font myFont = new Font("arial", 14, FontStyle.Regular)

For a font family I can request the font metrics, like line spacing, but I can't change them. And for a specific font there is no way (so far as I can tell) to request the font metrics.

I'm especially interested in trying to increase the line spacing, without having to revert to using graphics.DrawString() and a lot of font measuring.

So far I only found this MSDN page: http://msdn.microsoft.com/en-us/library/xwf9s90b.aspx

Roy T.
  • 9,429
  • 2
  • 48
  • 70
  • I think, it depends on the context. Are you trying to do this in a RichTextBox? Winforms or WPF? – Daniel Hilgarth May 02 '11 at 11:59
  • I'm trying to do this for a label. (Which because of the maxsize property spans multiple lines). – Roy T. May 02 '11 at 12:01
  • 1
    It isn't possible. You need to roll your own solution. Hints and example code for WinForms can be found here: http://stackoverflow.com/questions/5068752/how-to-change-spaces-between-lines-in-winforms-label – Daniel Hilgarth May 02 '11 at 12:03
  • I was afraid of that. Maybe I should just edit the font externally once. – Roy T. May 02 '11 at 12:08
  • Eh... Doesn't like the best idea, especially, if it is a default font... – Daniel Hilgarth May 02 '11 at 12:09
  • It's a specific one-time use non-default font, creating a custom label class would of course be neater, but I can just hand this font back to the designer to fix this, which would be a lot quicker and less bug prone. – Roy T. May 02 '11 at 12:19
  • If you have control over the font anyway and always need this line spacing, then yes, fixing the font is the way to go :-) – Daniel Hilgarth May 02 '11 at 12:19

0 Answers0