Windows Mobile 下 自适应大小的 Label
2008-10-22 15:44
162 查看
在mobile下面,经常要显示一些信息,由于是手持设备,一般需要显示的大些才好看见。为此,我写了一个自适应大小的函数,修改Label的字体,实现信息的最大显示。
函数使用方法:
Value 要显示的内容
LabShow 要显示到的Label类。
字体最小为8
void setTitleShow(string value, Label labShow)
{
SizeF MyFontSize = SizeF.Empty;
Font MyFont = null;
string strTest;
Bitmap bmp = new Bitmap(50, 50);
Graphics g = Graphics.FromImage(bmp);
strTest = value;
Rectangle MyRect = new Rectangle(0, 0, labShow.Width, labShow.Height);
MyFont = new Font("Tahoma", MyRect.Height, FontStyle.Regular);
MyFontSize = g.MeasureString(strTest, MyFont);
while ((MyFontSize.Width > MyRect.Width || MyFontSize.Height > MyRect.Height) && (MyFont.Size > 8))
{
MyFont = new Font("Tahoma", (MyFont.Size - .01F), FontStyle.Regular);
MyFontSize = g.MeasureString(strTest, MyFont);
}
labShow.Font = MyFont;
labShow.Text = value;
}
函数使用方法:
Value 要显示的内容
LabShow 要显示到的Label类。
字体最小为8
void setTitleShow(string value, Label labShow)
{
SizeF MyFontSize = SizeF.Empty;
Font MyFont = null;
string strTest;
Bitmap bmp = new Bitmap(50, 50);
Graphics g = Graphics.FromImage(bmp);
strTest = value;
Rectangle MyRect = new Rectangle(0, 0, labShow.Width, labShow.Height);
MyFont = new Font("Tahoma", MyRect.Height, FontStyle.Regular);
MyFontSize = g.MeasureString(strTest, MyFont);
while ((MyFontSize.Width > MyRect.Width || MyFontSize.Height > MyRect.Height) && (MyFont.Size > 8))
{
MyFont = new Font("Tahoma", (MyFont.Size - .01F), FontStyle.Regular);
MyFontSize = g.MeasureString(strTest, MyFont);
}
labShow.Font = MyFont;
labShow.Text = value;
}
相关文章推荐
- iOS label根据显示内容自适应大小 时间 2015-12-04 16:39:00 博客园-原创精华区 原文 http://www.cnblogs.com/czq1989/p/5019720.
- iOS label自适应大小
- ios开发系列之label自适应大小
- Label自适应文字大小
- ios7Label自适应大小
- 如何让label大小自适应字体大小
- UIlabel文字大小自适应label宽度变大变小
- label自适应文本大小
- iOS7 Label自适应文字内容大小
- iOS label根据显示内容自适应大小
- iOS label根据显示内容自适应大小
- ios7Label自适应大小
- QT画图教程1:实现给label上面显示图并且让图自适应控件大小
- Qt 根据Label大小无形变的自适应居中显示图像
- Label或Button自适应宽高或文字大小
- Qt label自适应窗体大小
- iOS label根据显示内容自适应大小
- label 自适应大小
- pixmap和label设置图片自适应大小
- ios8以后Label自适应大小