DrawString(String,IDrawingFont,IDrawingPen,IDrawingBrush,IGraphicsPath) Метод (DrawingEngine)
Рисует указанную строку Unicode вдоль указанного пути с помощью указанных объектов
IDrawingBrush и
IDrawingFont.
Вот пример, показывающий, как нарисовать строку с помощью движка рисования.
''' <summary>
''' Draws a string along graphics path on specified drawing engine.
''' </summary>
''' <param name="drawingEngine">Drawing engine.</param>
''' <param name="area">Area to draw objects in.</param>
Public Shared Sub DrawStringAlongPathExample(drawingEngine As DrawingEngine, area As RectangleF)
' set font size
Dim fontSize As Single = (area.Width + area.Height) * 0.06F
' create graphics path, text font and brush
Using path As IGraphicsPath = drawingEngine.DrawingFactory.CreateGraphicsPath()
Using font As IDrawingFont = drawingEngine.DrawingFactory.CreateFont("Arial", fontSize, False, False)
Using brush As IDrawingSolidBrush = drawingEngine.DrawingFactory.CreateSolidBrush(Color.Red)
Dim curvePoints As PointF() = New PointF() {New PointF(area.X + area.Width * 0.15F, area.Y + area.Height * 0.5F), New PointF(area.X + area.Width * 0.25F, area.Y + area.Height * 0.2F), New PointF(area.X + area.Width * 0.4F, area.Y + area.Height * 0.2F), New PointF(area.X + area.Width * 0.5F, area.Y + area.Height * 0.5F), New PointF(area.X + area.Width * 0.6F, area.Y + area.Height * 0.8F), New PointF(area.X + area.Width * 0.75F, area.Y + area.Height * 0.8F), _
New PointF(area.X + area.Width * 0.85F, area.Y + area.Height * 0.5F)}
' add path elements
path.AddCurve(curvePoints)
' draw a string along graphics path
drawingEngine.DrawString("Draw string along path example!", font, Nothing, brush, path)
End Using
End Using
End Using
End Sub
/// <summary>
/// Draws a string along graphics path on specified drawing engine.
/// </summary>
/// <param name="drawingEngine">Drawing engine.</param>
/// <param name="area">Area to draw objects in.</param>
public static void DrawStringAlongPathExample(DrawingEngine drawingEngine, RectangleF area)
{
// set font size
float fontSize = (area.Width + area.Height) * 0.06f;
// create graphics path, text font and brush
using (IGraphicsPath path = drawingEngine.DrawingFactory.CreateGraphicsPath())
using (IDrawingFont font = drawingEngine.DrawingFactory.CreateFont("Arial", fontSize, false, false))
using (IDrawingSolidBrush brush = drawingEngine.DrawingFactory.CreateSolidBrush(Color.Red))
{
PointF[] curvePoints = new PointF[]
{
new PointF(area.X + area.Width * 0.15f, area.Y + area.Height * 0.5f),
new PointF(area.X + area.Width * 0.25f, area.Y + area.Height * 0.2f),
new PointF(area.X + area.Width * 0.40f, area.Y + area.Height * 0.2f),
new PointF(area.X + area.Width * 0.5f, area.Y + area.Height * 0.5f),
new PointF(area.X + area.Width * 0.6f, area.Y + area.Height * 0.8f),
new PointF(area.X + area.Width * 0.75f, area.Y + area.Height * 0.8f),
new PointF(area.X + area.Width * 0.85f, area.Y + area.Height * 0.5f)
};
// add path elements
path.AddCurve(curvePoints);
// draw a string along graphics path
drawingEngine.DrawString("Draw string along path example!", font, null, brush, path);
}
}
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5