开发者

how to change spaces between lines in winforms label?

开发者 https://www.devze.com 2023-02-12 15:40 出处:网络
I have a label with unknown text. the text contains \\n. I want a bigger space 开发者_运维百科between the \\n lines. How can I set it?You can create custom label component and override it\'s measuring

I have a label with unknown text. the text contains \n. I want a bigger space 开发者_运维百科between the \n lines. How can I set it?


You can create custom label component and override it's measuring and painting, here you can find a snippet of a paint method which implements line spacing.

Edit: adding a snippet here in case the link is dead:

string text = "Sri Lanka";
Graphics g = e.Graphics;
Font font = new Font("Arial", 10);
Brush brush = new SolidBrush(Color.Black);
float lineSpacing = 0.5f;

SizeF size = g.MeasureString("A", font);

float pos = 0.0f;
for ( int i = 0; i < text.Length; ++i )
{
    string charToDraw = new string(textIdea, 1);
    g.DrawString(charToDraw, font, brush, pos, 0.0f);
    SizeF sizeChar = g.MeasureString(charToDraw, font);
    pos +=  sizeChar.Width + size.Width * lineSpacing;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消