C# 如何设置行距 Graphics.DrawString
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/342254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set line spacing Graphics.DrawString
提问by Ronnie
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?
我到达在 retangle 内的多行上输出一个字符串,但还没有找到减少或扩大行距的方法。怎么做?
采纳答案by grepsedawk
回答by Dave R.
This Microsoft forum posting may be helpful:
此 Microsoft 论坛帖子可能会有所帮助:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1507414&SiteID=1
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.
这显示了如何使用 MeasureString 来确定每行适合多少文本,然后使用它逐行逐步呈现整个矩形的内容。不幸的是,我认为没有内置的行间距属性,因此您必须采用手动方法。帖子的作者使用字体的高度 * 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:
还值得研究 StringFormatFlags - 您需要确保您的 DrawString 和 MeasureString 调用使用相同的 StringFormat 以便呈现和测量一致:
http://msdn.microsoft.com/en-us/library/system.drawing.stringformatflags.aspx
http://msdn.microsoft.com/en-us/library/system.drawing.stringformatflags.aspx