Skip to main content
A newer version of this page is available. .

RichEditControl.GetBoundsFromPosition(DocumentPosition) Method

Gets bounds of the character at the specified position.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.XtraRichEdit.v19.1.dll

Declaration

public Rectangle GetBoundsFromPosition(
    DocumentPosition pos
)

Parameters

Name Type Description
pos DocumentPosition

A target position.

Returns

Type Description
Rectangle

the area occupied by a character, or the System.Drawing.Rectangle.Empty value if the bounds could not be determined.

Remarks

You can use the GetBoundsFromPosition method only for the currently visible document part. If the specified position is not displayed, the method returns a System.Drawing.Rectangle.Empty value.

The rectangle’s location and size are expressed in currently specified measurement units. Use the Document.Unit property to change the measurement units.

Example

The following code highlights the line containing the caret. The Document.CaretPosition property determines the caret position, the RichEditControl.GetBoundsFromPosition method calculates the caret screen coordinates.

The RichEditControl instance is passed to the BarItem.ItemClick event handler using the BarItem.Tag property.

static void richEditControl_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {
    RichEditControl richEdit = sender as RichEditControl;
    DocumentPosition pos = richEdit.Document.CaretPosition;
    if(pos != null) {
        System.Drawing.Rectangle rect = DevExpress.Office.Utils.Units.DocumentsToPixels(
            richEdit.GetBoundsFromPosition(pos), 
            richEdit.DpiX, 
            richEdit.DpiY);

        Section firstSection = richEdit.Document.Sections[0];
        int pageWidth = Convert.ToInt32(firstSection.Page.Width - firstSection.Margins.Left - firstSection.Margins.Right);
        e.Graphics.DrawLine(System.Drawing.Pens.Red, 
            new System.Drawing.Point(0, rect.Bottom), 
            new System.Drawing.Point(pageWidth, rect.Bottom));
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetBoundsFromPosition(DocumentPosition) 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