DrawText(String,IDrawingFont,IDrawingBrush,PointF,TextLayoutProperties) Метод (DrawingEngine)
Рисует указанный текст в указанной точке
System.Drawing.PointF, используя указанные объекты
IDrawingBrush и
IDrawingFont.
Вот пример, показывающий, как рисовать текст с помощью движка рисования.
''' <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);
}
}
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5