Auto Sized Label control for the compact framework:
I noticed that there is no solution for an autosized label (auto width & height)
so i build my example for this control:
public class AutoSizeLabel : Label
{
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
ReCalculateSize();
}
}
public override System.Drawing.Font Font
{
get
{
return base.Font;
}
set
{
base.Font = value;
ReCalculateSize();
}
}
private void ReCalculateSize()
{
using (Control control = new Control())
{
using (Graphics g = control.CreateGraphics())
{
SizeF size = g.MeasureString(base.Text, base.Font);
base.Width = (int)size.Width + 1;
base.Height = (int)size.Height + 1;
}
}
}
}
i hope it will help you...
No comments:
Post a Comment