Gestures don't work with controls inside ScrollBox and descendants (I don't know, why). You should use ListBox.Touch
, ListBox.OnGesture
and analyze Selected
property:
ListBox1.Touch.GestureManager := FmyGestureManager;
ListBox1.Touch.InteractiveGestures := [TInteractiveGesture.LongTap];
ListBox1.OnGesture := ListBox1Gesture;
procedure THeaderFooterForm.ListBox1Gesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean);
begin
if (Sender = ListBox1) and Assigned(ListBox1.Selected) then
begin
lblMenuToolBar.Text := 'Handled' + ListBox1.Selected.Text;
Handled := True;
end;
end;
Or, more complex method - find item by gesture location:
procedure THeaderFooterForm.ListBox1Gesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean);
var
c: IControl;
ListBox: TListBox;
lbxPoint: TPointF;
ListBoxItem: TListBoxItem;
begin
c := ObjectAtPoint(EventInfo.Location);
if Assigned(c) then
if Assigned(c.GetObject) then
if c.GetObject is TListBox then
begin
ListBox := TListBox(c.GetObject);
lbxPoint := ListBox.AbsoluteToLocal(EventInfo.Location);
ListBoxItem := ListBox.ItemByPoint(lbxPoint.X, lbxPoint.Y);
if Assigned(ListBoxItem) then
lblMenuToolBar.Text := 'Handled ' + ListBoxItem.Text;
Handled := True;
end;
end;