Gets the extent (both width and height) of the string draw by the GdiGraphics.DrawString method.

Namespace: Aurigma.GraphicsMill.Drawing
Assembly: Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)

Syntax

Visual Basic

Public Function MeasureString ( _
	text As String _
) As SizeF

C#

public SizeF MeasureString(
	string text
)

Parameters

text

Type: System..::.String

String you want to measure.

Return Value

Dimensions of the rectangle occupied with string when it will be drawn.

Examples

Visual Basic

' Create Bitmap object.
Dim bitmap As New Aurigma.GraphicsMill.Bitmap(250, 40, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

bitmap.Unit = Aurigma.GraphicsMill.Unit.Point

Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = bitmap.GetGdiGraphics()

' Fill background.
graphics.FillRectangle(New Aurigma.GraphicsMill.Drawing.SolidBrush( _
    Aurigma.GraphicsMill.RgbColor.White), 0, 0, bitmap.Width, bitmap.Height)

' Adjust font settings.
Dim timesFont As New Aurigma.GraphicsMill.Drawing.Font("Times New Roman", 25, False, True)

Dim text As String = "Single-line text..."

' Measure the text size.
Dim size As System.Drawing.SizeF = timesFont.MeasureString(text)

Dim blackBrush As New Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black)

graphics.DrawString(text, timesFont, blackBrush, 0, 0)

Dim redBrush As New Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Red)

Dim tahomaFont As New Aurigma.GraphicsMill.Drawing.Font("Tahoma", 12)

text = "Height: " & size.Height
graphics.DrawString(text, tahomaFont, redBrush, size.Width + 1, 20)

text = "Width: " & size.Width
graphics.DrawString(text, tahomaFont, redBrush, size.Width + 1, 0)

C#

// Create Bitmap object.
Aurigma.GraphicsMill.Bitmap bitmap = 
    new Aurigma.GraphicsMill.Bitmap(250, 40, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

bitmap.Unit = Aurigma.GraphicsMill.Unit.Point;

Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();

// Fill background.
graphics.FillRectangle(new Aurigma.GraphicsMill.Drawing.SolidBrush( 
    Aurigma.GraphicsMill.RgbColor.White), 0, 0, bitmap.Width, bitmap.Height);

// Adjust font settings.
Aurigma.GraphicsMill.Drawing.Font timesFont = 
    new Aurigma.GraphicsMill.Drawing.Font("Times New Roman", 25, false, true);

string text = "Single-line text...";

// Measure the text size.
System.Drawing.SizeF size = timesFont.MeasureString(text);

Aurigma.GraphicsMill.Drawing.SolidBrush blackBrush = 
    new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black);

graphics.DrawString(text, timesFont, blackBrush, 0, 0);

Aurigma.GraphicsMill.Drawing.SolidBrush redBrush = 
    new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Red);

Aurigma.GraphicsMill.Drawing.Font tahomaFont = new 
    Aurigma.GraphicsMill.Drawing.Font("Tahoma", 12); 

text = "Height: " + size.Height.ToString();
graphics.DrawString(text, tahomaFont, redBrush, size.Width + 1, 20);

text = "Width: " + size.Width.ToString();
graphics.DrawString(text, tahomaFont, redBrush, size.Width + 1, 0);