HitTest 运用:cxGrid中判断是点击了空白区域还是Tab

我们可以使用HitTest来确定鼠标在网格中点击的位置。使用以下代码来确定单击网格选项卡区域的空白区域:




uses cxGridDetailsSite;  

   

type   

   TcxGridAccess = class(TcxGrid);   

   TcxGridDetailsSiteTopTabsViewInfoAccess = class(TcxGridDetailsSiteTopTabsViewInfo);   

   

   

procedure TForm1.FormCreate(Sender: TObject);   

begin   

   TcxGridAccess(cxGrid1).OnMouseDown := OnMouseDownHandler;   

end;   

   

procedure TForm1.OnMouseDownHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);   

var   

   AHitTest: TcxCustomGridHitTest;   

   AViewInfo: TcxGridDetailsSiteTopTabsViewInfoAccess;   

begin   

   AHitTest := TcxGrid(Sender).ViewInfo.GetHitTest(X,Y);   

   if AHitTest is TcxgridDetailsSiteTabHitTest then   

   begin   

    if TcxgridDetailsSiteTabHitTest(AHitTest).ViewInfo is TcxgridDetailsSiteTopTabsViewInfo then   

    begin   

      AViewInfo := TcxGridDetailsSiteTopTabsViewInfoAccess(TcxGridDetailsSiteTabHitTest(AHitTest).ViewInfo);   

      if PtInRect(AViewInfo.TabsViewInfo.TabsAreaRect, Point(X,Y)) and (AViewInfo.TabsViewInfo.IndexOfTabAt(X,Y) = -1) then   

        Caption := '点击了空白区域'   

      else   

        Caption := '点击了一个Tab选项卡;   

    end;   

   end;   

end;


联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678