如何根据内容和字体调整标签高度? [英] how to resize label height according to it's content and font?

查看:87
本文介绍了如何根据内容和字体调整标签高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public int CalculateHeight(Label lbl)
{
    Graphics g = lbl.CreateGraphics();
    return Convert.ToInt32(g.MeasureString(lbl.Text, lbl.Font).Width);
}

private void button1_Click(object sender, EventArgs e)
{
    label1.Text = "The Computer location is now called This PC, and you can still use the Documents, Music, Pictures, and Videos folders to save your files. You just browse to these folders differently in File Explorer. To browse the locations on your PC, including the folders that used to appear under Libraries, expand This PC in the left pane. ";
    //label1.Text = "The Computer location is now called This PC, and you can still use the Documents, Music, Pictures, and Videos folders to save your files.";
    label1.Height = CalculateHeight(label1) / 14;
    MessageBox.Show(label1.Height.ToString());
}






此代码中的
我无法确定标签的新高度。

请帮助我..

先谢谢。




in this code I cant decide the label's new height.
Please Help me..
Thanks in Advance.

推荐答案

参见 http://stackoverflow.com/questions/15706148/auto-size-of-label-height- and-width-in-c-sharp [ ^ ]


这篇关于如何根据内容和字体调整标签高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆