FMX.Controls.TControl.HitTest

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property HitTest: Boolean read FHitTest write SetHitTest default True;

C++

__property bool HitTest = {read=FHitTest, write=SetHitTest, default=1};

Properties

Type Visibility Source Unit Parent
property public
FMX.Controls.pas
FMX.Controls.hpp
FMX.Controls TControl

Description

Enables the control to capture mouse events.

  • If you set HitTest to True, this control captures all mouse events. The example below shows the use of HitTest for an OnClick event.
  • If you set HitTest to False, the mouse events will pass through this control, so that a control laid out behind this one receives the mouse events instead of this control.
Note: The HitTest enables all mouse-related events, which also include the display of Hints and Hint-related events.

For most controls, HitTest is True by default. However, this is not true for all the controls. For example, for TLabel and TPathLabel, HitTest is False by default; these two controls do not capture the mouse-related events unless you set HitTest to True.

Example of HitTest

1. On a form, place a TPanel component.

2. Inside the panel, place a TPathLabel component.

3. Implement the OnClick event for both the TPanel and the TPathLabel:

procedure TForm1.Panel1Click(Sender: TObject);
begin
  ShowMessage('OnClick event fired for TPanel');
end;
procedure TForm1.PathLabel1Click(Sender: TObject);
begin
  ShowMessage('OnClick event fired for TPathLabel');
end;

4. Set the TPathLabel HitTest property to False (this is the default setting). Run the application and click the label. The OnClick event is fired for the panel (not the label).

5. Set the TPathLabel HitTest property to True. Run the application and click the label. The OnClick event is fired for the TPathLabel.

See Also