VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.Drawing Namespace / DrawingEngine Class / DrawText Methods / DrawText(String,IDrawingFont,IDrawingBrush,RectangleF,TextLayoutProperties) Method
Syntax Exceptions Example Requirements SeeAlso
In This Topic
DrawText(String,IDrawingFont,IDrawingBrush,RectangleF,TextLayoutProperties) Method (DrawingEngine)
In This Topic
Draws the specified text at the specified System.Drawing.RectangleF using the specified IDrawingBrush and IDrawingFont objects.
Syntax
'Declaration

Public Overloads Sub DrawText( _
ByVal text
A text in Unicode encoding to draw.
As System.String, _
ByVal font
The IDrawingFont, which should be used for drawing text.
As IDrawingFont, _
ByVal brush
The IDrawingBrush, which should be used for drawing text.
As IDrawingBrush, _
ByVal rect
The System.Drawing.RectangleF of the drawn text.
As System.Drawing.RectangleF, _
ByVal layoutProperties
The TextLayoutProperties, which should be used for drawing text.
As TextLayoutProperties _
)

Parameters

text
A text in Unicode encoding to draw.
font
The IDrawingFont, which should be used for drawing text.
brush
The IDrawingBrush, which should be used for drawing text.
rect
The System.Drawing.RectangleF of the drawn text.
layoutProperties
The TextLayoutProperties, which should be used for drawing text.
Exceptions
ExceptionDescription
Thrown if font or brush is null.
Example

Here is an example that shows how to draw text using drawing engine.


''' <summary>
''' Draws text on specified drawing engine.
''' </summary>
''' <param name="drawingEngine">Drawing engine.</param>
''' <param name="area">Area to draw objects in.</param>
Public Shared Sub DrawTextExample(drawingEngine As DrawingEngine, area As RectangleF)
    ' set font size
    Dim fontSize As Single = (area.Width + area.Height) * 0.07F
    ' create rectangle to locate text
    Dim textRect As New RectangleF(area.X, area.Y, area.Width, area.Height)
    ' create properties for text layout
    Dim layoutProperties As New TextLayoutProperties(AnchorType.Center, True)

    ' create font and brush to draw text
    Using font As IDrawingFont = drawingEngine.DrawingFactory.CreateFont("Arial", fontSize, False, True)
        Using brush As IDrawingSolidBrush = drawingEngine.DrawingFactory.CreateSolidBrush(Color.Green)
            ' draw text
            drawingEngine.DrawText("Centered text with word wrap example!", font, brush, textRect, layoutProperties)
        End Using
    End Using
End Sub


/// <summary>
/// Draws text on specified drawing engine.
/// </summary>
/// <param name="drawingEngine">Drawing engine.</param>
/// <param name="area">Area to draw objects in.</param>
public static void DrawTextExample(DrawingEngine drawingEngine, RectangleF area)
{
    // set font size
    float fontSize = (area.Width + area.Height) * 0.07f;
    // create rectangle to locate text
    RectangleF textRect = new RectangleF(area.X, area.Y, area.Width, area.Height);
    // create properties for text layout
    TextLayoutProperties layoutProperties = new TextLayoutProperties(AnchorType.Center, true);

    // create font and brush to draw text
    using (IDrawingFont font = drawingEngine.DrawingFactory.CreateFont("Arial", fontSize, false, true))
    using (IDrawingSolidBrush brush = drawingEngine.DrawingFactory.CreateSolidBrush(Color.Green))
    {
        // draw text
        drawingEngine.DrawText("Centered text with word wrap example!", font, brush, textRect, layoutProperties);
    }
}

Requirements

Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also