Using System;
Using System. Data;
Using System. Configuration;
Using System. Linq;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. HtmlControls;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Xml. Linq;
Using System. Drawing;
Namespace NewsWebApp. Biz
{
Public class TextCount
{
System. Drawing. Font gdiFont;
System. Drawing. Graphics graphics;
Public Font
{
Get {return this. font ;}
Set
{
If (value = null)
Throw new ArgumentNullException ("value ");
If (this. font! = Value)
{
This. font = value;
This. gdiFont = null;
}
}
}
Font font;
/// <Summary>
/// Measure the text height by width
/// </Summary>
/// <Param name = "text"> text </param>
/// <Param name = "Textwidth"> text height </param>
/// <Returns> </returns>
Public float GetHeightByText (string text, int Textwidth)
{
Graphics g = Realize ();
Font stringFont = new Font ("Arial", 16 );
StringFormat newStringFormat = new StringFormat ();
NewStringFormat. FormatFlags = StringFormatFlags. LineLimit;
// Measure string.
SizeF stringSize = new SizeF ();
StringSize = g. MeasureString (text, stringFont, Textwidth, newStringFormat );
Return stringSize. Height;
}
Graphics Realize ()
{
If (this. graphics = null)
This. graphics = Graphics. FromHwnd (IntPtr. Zero );
This. graphics. PageUnit = GraphicsUnit. Point;
Return this. graphics;
}
}
}