Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Box

PageCanvas.DrawString(String, Font, RichEditBrushBase, Point, DocumentLayoutUnit) Method

Draws a custom string.

Namespace: DevExpress.XtraRichEdit.API.Layout

Assembly: DevExpress.RichEdit.v19.1.Core.dll

Declaration

public void DrawString(
    string str,
    Font font,
    RichEditBrushBase brush,
    Point point,
    DocumentLayoutUnit unit
)

Parameters

Name Type Description
str String

A custom string to be drawn.

font Font

Sets the string’s font parameters.

brush RichEditBrushBase

The RichEditBrushBase descendant that sets the string characters’ color and thickness.

point Point

Sets the string’s start point coordinates.

unit DocumentLayoutUnit

Specifies measurement units for string parameters.

Remarks

When you print or export documents, document objects may appear differently from the way they look on screen. To make them look the same in both outputs, set the DocumentLayoutUnit parameter to the same DocumentLayoutUnit value as the one specified for the document layout.

Note

Using this parameter is effective only if the drawn shape has coordinates and parameters represented by absolute values – coordinates represented by relative values already have the same measurement unit as the whole document layout.

Example

This code snippet illustrates the implementation of the PageCanvas.DrawLine and PageCanvas.DrawString methods. They draw two color lines and two strings in place of the header.

One line was drawn without setting the DocumentLayoutUnit parameter, the other was drawn with this parameter set to the same DocumentLayoutUnit value as the one specified for the document layout.

HeaderPainter Display

The line with the set parameter will look the same both in Print Preview and on display, whereas the other will look different in Print Preview.

HeaderPainter PrintPreview

Public Overrides Sub DrawHeader(ByVal header As LayoutHeader)
    If Form1.customDrawHeader = True Then

        Dim p1 As New Point(0, 0)
        Dim p2 As New Point(100, 100)
        Canvas.DrawLine(New RichEditPen(Color.Red, 5), p1, p2)
        Canvas.DrawString("Default Layout Unit", New Font("Comic Sans", 12), New RichEditBrush(Color.Red), New Point(0, 0))
        Dim p3 As New Point(0, 100)
        Dim p4 As New Point(100, 200)
        Canvas.DrawLine(New RichEditPen(Color.Blue, 5), p3, p4, DocumentLayoutUnit.Pixel)
        Canvas.DrawString("Layout Unit Specified", New Font("Comic Sans", 12), New RichEditBrush(Color.Blue), New Point(0, 100), DocumentLayoutUnit.Pixel)
    Else
        MyBase.DrawHeader(header)
    End If
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DrawString(String, Font, RichEditBrushBase, Point, DocumentLayoutUnit) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also