|
// � Copyright 2002, Pierre ARNAUD, OPaC bright ideas, Switzerland.
// All rights reserved.
namespace uk.org.aspellclark.common
{
public class StringTools
{
private StringTools() { }
static public System.Drawing.SizeF MeasureDisplayString(System.Drawing.Graphics graphics, string text, System.Drawing.Font font)
{
const int width = 32;
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap (width, 1, graphics);
System.Drawing.SizeF size = graphics.MeasureString (text, font);
System.Drawing.Graphics anagra = System.Drawing.Graphics.FromImage (bitmap);
int measured_width = (int) size.Width;
if (anagra != null)
{
anagra.Clear (System.Drawing.Color.White);
anagra.DrawString (text+"|", font, System.Drawing.Brushes.Black, width - measured_width, -font.Height / 2);
for (int i = width-1; i >= 0; i--)
{
measured_width--;
if (bitmap.GetPixel (i, 0).R == 0)
{
break;
}
}
}
return new System.Drawing.SizeF (measured_width, size.Height);
}
static public int MeasureDisplayStringWidth(System.Drawing.Graphics graphics, string text, System.Drawing.Font font)
{
return (int) MeasureDisplayString (graphics, text, font).Width;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.