在Delphi XE3中长按并选择手势

时间:2018-07-26 16:29:46

标签: delphi grid touch

为Windows 10平板电脑开发应用程序。使用TDrawGrid并想要实现两个手势: 1.长按(点击并按住,在触摸设备上为标准手势)。 2.在网格中的行中选择单元格(点击并按住,然后向右移动手指,这也是标准手势)。

现在我使用此代码:

procedure TfmMain.GridGesture(Sender: TObject;
  const EventInfo: TGestureEventInfo; var Handled: Boolean);
var
  ACol, ARow: Integer;
  ARect: TRect;
  X, Y: Integer;
  num: Integer;
begin
  if EventInfo.GestureID=igiPressAndTap then
  begin
    Handled := True;
    X := EventInfo.Location.X;
    Y := EventInfo.Location.Y;

    num := pagesBuildings.ActivePageIndex;
    if not ((pmCol<0) or (pmRow<0) or
      ((pmIsLeft) and (PagesDays[num][pmRow, pmCol][0].ReservID<=0)) or
      ((not pmIsLeft) and (PagesDays[num][pmRow, pmCol][1].ReservID<=0))) then
        pmGrid.Popup(X, Y);
  end;

  if EventInfo.GestureID=igiPan then
  begin
    Handled := True;
    X := EventInfo.Location.X;
    Y := EventInfo.Location.Y;

    if gfBegin in EventInfo.Flags then
    begin
      (Sender as TDrawGrid).MouseToCell(X, Y, ACol, ARow);
      ARect := (Sender as TDrawGrid).CellRect(ACol, ARow);

      pmIsLeft := X<(ARect.Left+((ARect.Right-ARect.Left) div 2));
      pmCol := ACol;
      pmRow := ARow;

      ChooseDaysInGridRowIndex := ARow;
      SetLength(ChooseDays, 0);
    end
    else
    begin
      if gfInertia in EventInfo.Flags then
      begin
        (Sender as TDrawGrid).MouseToCell(X, Y, ACol, ARow);
        if (ChooseDaysInGridRowIndex>0) and
          (ChooseDaysInGridRowIndex<=(Sender as TDrawGrid).RowCount-1) and
          ((PagesDays[pagesBuildings.ActivePageIndex][ARow, ACol][0].ReservID<=0) or
            ((Length(ChooseDays)=0) and ((PagesDays[pagesBuildings.ActivePageIndex][ARow, ACol][1].ReservID<=0))))     then
        begin
          SetLength(ChooseDays, Length(ChooseDays)+1);
          ChooseDays[High(ChooseDays)] := Point(ACol, ChooseDaysInGridRowIndex);

          InvalidateRect((Sender as TDrawGrid).Handle,
            (Sender as TDrawGrid).CellRect(ACol, ARow),
            True);
        end;
        ChooseDaysInGrid := True;
      end
      else
      begin
        if gfEnd in EventInfo.Flags then
        begin
          if ChooseDaysInGrid then
          begin
            (Sender as TDrawGrid).MouseToCell(X, Y, ACol, ARow);
            ChooseDaysInGrid := False;

            fmGuestArrival.roomID := GridRowTitles[(Sender as TDrawGrid).Tag][ARow].RoomID;
        //      Integer((Sender as TDrawGrid).Objects[0, ARow]);

            if Length(ChooseDays)>0 then
            begin
              fmGuestArrival.dateArrival.DateTime :=
                IncDay(StartDatePeriod, ChooseDays[0].X-1);
              if Length(ChooseDays)>1 then
              begin
                fmGuestArrival.dateDeparture.DateTime :=
                  IncDay(StartDatePeriod, ChooseDays[High(ChooseDays)].X - 1);
              end
              else
              begin
                fmGuestArrival.dateDeparture.DateTime :=
                  IncDay(fmGuestArrival.dateArrival.DateTime, 1);
              end;
            end;

            fmGuestArrival.IsEditing := False;
            fmGuestArrival.cbStatus.ItemIndex := 0;
            fmGuestArrival.ShowModal;
          end;
        end;
      end;
    end;
  end;
end;

长按时,我使用igiPressAndTap。有用。 对于某些单元,请尝试使用igiPan。选择有效,但在这种情况下不起作用。 据我了解,对于选择手势,我应该结合使用长按和平移手势。怎么做? 我使用的是Delphi XE3(在InteractiveGestures中没有长按手势)。该应用程序将在Windows 10上运行。

0 个答案:

没有答案