调整标签的文本大小当文本得到了比标签尺寸长? [英] Resize text size of a label when the text got longer than the label size?

查看:137
本文介绍了调整标签的文本大小当文本得到了比标签尺寸长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签,显示文件名..我不得不将标签设置为False设计​​的自动调整大小。结果
因此,当文件名的文本比标注尺寸变长..它得到了削减像的图片。

I have a label that shows the file name .. I had to set AutoSize of the label to False for designing.
So when the file name text got longer than label size.. it got cut like in the picture.

label1.Size = new Size(200, 32);
label1.AutoSize = false;

如何自动执行我重新大小的文字,以适合标签尺寸..当文本大于标签尺寸长?

How do I re-size the text automatically to fit the label size .. when the text is longer than the label size?

推荐答案

您可以在下面用我的code片段。系统需要一些环基于文本大小来计算标签的字体。

You can use my code snippet below. System needs some loops to calculate the label's font based on text size.

while(label1.Width < System.Windows.Forms.TextRenderer.MeasureText(label1.Text, 
     new Font(label1.Font.FontFamily, label1.Font.Size, label1.Font.Style)).Width)
{
    label1.Font = new Font(label1.Font.FontFamily, label1.Font.Size - 0.5f, label1.Font.Style);
}

这篇关于调整标签的文本大小当文本得到了比标签尺寸长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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