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

RichEditControl.GetBoundsFromPosition(DocumentPosition) Method

Gets the rectangle representing the character at the specified position.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.XtraRichEdit.v18.1.dll

Declaration

public Rectangle GetBoundsFromPosition(
    DocumentPosition pos
)

Parameters

Name Type Description
pos DocumentPosition

A DocumentPosition, specifying the position in the document.

Returns

Type Description
Rectangle

A Rectangle representing the area occupied by a character or the System.Drawing.Rectangle.Empty value if the bounds could not be determined. Measured in the units that are in effect.

Remarks

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

The location and size of the resulting rectangle are expressed in measurement the units which are in effect for the current document. To change the unit of measurement, use the Document.Unit property.

Example

The following code highlights the line in which the caret is located. The caret position is determined by the Document.CaretPosition property, the caret screen coordinates are calculated using the RichEditControl.GetBoundsFromPosition method.

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