-------------------------------
SizeF headingSize;
SizeF subHeadingSize;
// Measure string sizes
// Heading size
headingSize = MeasureString(heading, this.headingLabel.Width, headingLabel.Font);
this.headingLabel.Size = headingSize.ToSize();
// Subheading (size will be zero if singleMessage)
subHeadingSize = MeasureString(subHeading, this.subHeadingLabel.Width, subHeadingLabel.Font);
------------------------------------------------------------
private Size MeasureString(string str, int maxWidth, Font font)
{
using (Graphics g = this.CreateGraphics())
{
SizeF strRectSizeF = g.MeasureString(str, font, maxWidth);
g.Dispose();
return new Size((int)Math.Ceiling(strRectSizeF.Width), (int)Math.Ceiling(strRectSizeF.Height));
}
}
|