PageCanvas.ConvertToDrawingLayoutUnits(Rectangle, DocumentLayoutUnit) Method
Converts an object’s measurement units to the specified ones.
Namespace: DevExpress.XtraRichEdit.API.Layout
Assembly: DevExpress.RichEdit.v24.2.Core.dll
NuGet Package: DevExpress.RichEdit.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
rect | Rectangle | A Rectangle structure that will be measured in the specified unit. |
unit | DocumentLayoutUnit | Specifies measurement units for structure parameters. |
Returns
Type | Description |
---|---|
Rectangle | A Rectangle structure that is the original rectangle, converted to specific document layout units. |
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
This method is effective only if the drawn shape has coordinates and parameters represented by absolute values. There is no need to convert parameters represented by relative values – they are already measured in the same unit as the document layout.
Example
This code snippet illustrates the implementation of the PageCanvas.ConvertToDrawingLayoutUnits method.
In this example, a custom colored rectangle is drawn. The PageCanvas.ConvertToDrawingLayoutUnits method converts its parameters to the same measurement units as the one specified for the document layout. It makes the drawn figure appear the same in Print Preview and on the display:
If the method is not used and the rectangle’s parameters are not converted, it will appear as illustrated below:
Public Overrides Sub DrawPage(ByVal page As LayoutPage)
If Form1.customDrawPage = True Then
Dim inlineRect As New Rectangle(100, 100, 150, 200)
Canvas.DrawRectangle(New RichEditPen(Color.Aquamarine, Canvas.ConvertToDrawingLayoutUnits(4, DocumentLayoutUnit.Pixel)), Canvas.ConvertToDrawingLayoutUnits(inlineRect, DocumentLayoutUnit.Pixel))
End If
MyBase.DrawPage(page)
End Sub
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ConvertToDrawingLayoutUnits(Rectangle, 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.