|
// � Copyright 2002, Pierre ARNAUD, OPaC bright ideas, Switzerland.
// All rights reserved.
namespace SynapticEffect.Forms
{
public class HelperTools
{
private HelperTools() { }
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 article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
Independent software development for clients including Microsoft. Design and development of modules for financial reporting and business intelligence.