Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

RichEditHitTestResult Class

Provides options used to retrieve information about the layout element located under the hit point.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.RichEdit.v24.2.Core.dll

NuGet Package: DevExpress.RichEdit.Core

#Declaration

public class RichEditHitTestResult

#Remarks

Use the HitTestManager.HitTest method to retrieve the RichEditHitTestResult instance.

Tip

Refer to the following example to learn how to solve the same task using the WPF RichEditControl: Show a ToolTip that contains information about a document layout element located under the cursor position

#Example

if (!e.SelectedControl.Equals(richEditControl1))
    return;

//Obtain the mouse cursor's layout position on the page and the current page index:
PageLayoutPosition pageLayoutPosition = richEditControl1.ActiveView.GetDocumentLayoutPosition(e.ControlMousePosition);
if (pageLayoutPosition == null)
    return;            

Point point = pageLayoutPosition.Position;  
int pageIndex = pageLayoutPosition.PageIndex;
LayoutPage layoutPage = richEditControl1.DocumentLayout.GetPage(pageIndex);

//Create a HitTestManager instance: 
HitTestManager hitTest = new HitTestManager(richEditControl1.DocumentLayout);

//Perform the hit test and pass the result to the RichEditHitTestResult object:
RichEditHitTestResult result = hitTest.HitTest(layoutPage, point);
if (result != null)
{
    //Retrieve the current layout element type:
    LayoutElement element = result.LayoutElement;
    string text = element.Type.ToString();

    //Obtain the the text character and its bounds under the mouse position              
    if (element.Type == LayoutType.CharacterBox)
    {
        text += String.Format(" : \"{0}\"", (element as CharacterBox).Text);
        text += GetBounds(element);
        if (element.Parent.Type == LayoutType.PlainTextBox)
        {
            text += String.Format("\r\nPlainTextBox : \"{0}\"", (element.Parent as PlainTextBox).Text);
            text += GetBounds(element.Parent);
        }
    }
    else
    {
        //Get the hovered element's bounds:
        text += GetBounds(element);
    }

    //Get the element's location:
    string title = GetLocation(element);

    //Display all retrieved information in the tooltip:
    e.Info = new ToolTipControlInfo(element.Bounds, text, title, ToolTipIconType.Information);

}

#Inheritance

Object
RichEditHitTestResult
See Also