触摸屏上的TDrawGrid中的OnMouseMove

时间:2018-07-17 15:12:39

标签: delphi grid touch

在触摸屏Windows平板电脑上使用程序。有一个网格,我们需要在其中选择一些单元格:将光标置于单元格上方,单击鼠标左键,按住不放,将鼠标拉到一侧,然后释放鼠标左键(同时在OnDrawCell是绘制单元格)。 用鼠标或笔记本的触摸板效果很好。但是在平板电脑的触摸屏上根本不起作用。

我使用TDrawGrid和OnMouseDown,OnMouseMove,OnMouseUp事件。 在Shift中,使用所有选项:ssLeft,ssTouch,ssPen。查看完整的代码:

procedure TfmMain.GridMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  ACol, ARow: Integer;
  ARect: TRect;
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;
  if (ssLeft in Shift) or (ssTouch in Shift) or (ssPen in Shift) then
  begin
    ChooseDaysInGridRowIndex := ARow;
SetLength(ChooseDays, 0);
  end;
end;

procedure TfmMain.GridMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  ACol, ARow: Integer;
begin
  if (ssLeft in Shift) or (ssTouch in Shift) or (ssPen in Shift) 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;
end;

procedure TfmMain.GridMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  ACol, ARow: Integer;
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;

1 个答案:

答案 0 :(得分:0)

通过添加GesturingTGestureManager)来添加GestureManager1支持。然后将GestureManager1分配给Touch.GestureManager的{​​{1}}属性。打开TDrawGrid的TDrawGrid属性,然后选择要通知的手势。创建一个Touch.Gestures.Standard事件并根据需要添加代码。

详细信息为documented by Embarcadero