HitTestManager.HitTest(LayoutPage, Point, HitTestSearchOption) Method
Returns specific document elements located under the test point.
Namespace: DevExpress.XtraRichEdit
Assembly: DevExpress.RichEdit.v24.2.Core.dll
NuGet Package: DevExpress.RichEdit.Core
Declaration
public RichEditHitTestResult HitTest(
LayoutPage page,
Point point,
HitTestSearchOption findOption = HitTestSearchOption.Exact
)
Parameters
Name | Type | Description |
---|---|---|
page | LayoutPage | A LayoutPage object indicating the page to be searched. |
point | Point | The Point object that is the test point. |
Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
findOption | HitTestSearchOption | Exact | One of the HitTestSearchOption enumeration values specifying the search accuracy. |
Returns
Type | Description |
---|---|
RichEditHitTestResult | A RichEditHitTestResult object containing information about the determined element. |
Remarks
Pass the findOptions parameter to set the accuracy of the hit test. The HitTest method uses the HitTestSearchOption.Exact value as the findOptions parameter by default and retrieves information about the element located exactly under the hit test point. Passing the HitTestSearchOption.Nearest value makes the HitTest method return the information about the element that is the nearest to the test point.
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);
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the HitTest(LayoutPage, Point, HitTestSearchOption) 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.