How to set line spacing Graphics.DrawString

后端 未结 2 1712
独厮守ぢ
独厮守ぢ 2020-12-06 11:39

I arrive to output a string on multiple lines inside a retangle but haven\'t find a way to reduce or enlarge the line spacing. How to do that?

相关标签:
2条回答
  • 2020-12-06 11:55

    This MSDN should help you. Line spacing is a result of the Font you are using. You may need to break your DrawString commands up into multiple calls if you need custom line spacing.

    0 讨论(0)
  • 2020-12-06 12:00

    This Microsoft forum posting may be helpful:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1507414&SiteID=1

    This shows how MeasureString can be used to determine how much of your text will fit on each line, then using this to progressively render the entire rectangle's contents line by line. Unfortunately I don't think there's a built-in line spacing property, so you'll have to go for the manual approach. The post's author uses the font's Height * 1.5.

    It's also worth researching StringFormatFlags - you'll need to make sure both your DrawString and MeasureString calls use the same StringFormat so the rendering and measurement are consistent:

    http://msdn.microsoft.com/en-us/library/system.drawing.stringformatflags.aspx

    0 讨论(0)
提交回复
热议问题