Skip to main content

TdxCustomNavBar.GetLinkAtPos(TPoint) Method

Returns the link whose bounding rectangle is located under the specified point.

Declaration

function GetLinkAtPos(const pt: TPoint): TdxNavBarItemLink; virtual;

Parameters

Name Type
pt TPoint

Returns

Type
TdxNavBarItemLink

Remarks

Sometimes you may need to determine the element of the NavBar control located under the specified point. This can be used, for instance, if you need to invoke context menus for specific elements. In this case, you may handle the control’s OnMouseDown event to obtain the element under the mouse cursor position and decide whether to invoke a context menu.

The GetLinkAtPos function lets you determine the link under the specified point. If the pt parameter specifies a point located within a link’s bounding rectangle, the function returns the link. Otherwise, it returns nil. Thus you can compare the return value of the function to nil to determine whether the specified point is located over a link.

You can also use the GetLinkAtSelectedPos function to determine the link located under the specified point. This function returns a link if the point is over the link’s caption or image. Otherwise it returns nil. The image below illustrates the relation between the GetLinkAtPos and GetLinkAtSelectedPos functions.

The sample code below shows how to invoke a context menu for links corresponding to enabled items. It handles the OnMouseDown event of the NavBar control. The GetLinkAtPos function is used to determine the clicked link. (The code assumes that a popup menu component named PopupMenu1 resides on the form.)

procedure TfrmNavBarDemo.dxNavBarMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  APoint: TPoint;
  ALink: TdxNavBarItemLink;
begin
  if Button <> mbRight then Exit;
  APoint := Point(X, Y);
  ALink := dxNavBar.GetLinkAtPos(APoint);
  if ALink = nil then Exit;
  if ALink.Item.Enabled then
  begin
    APoint := dxNavBar.ClientToScreen(APoint);
    PopupMenu1.Popup(APoint.X, APoint.Y);
  end;
end;
See Also