我想在stringgrid中当鼠标用右键选中一个cell时去执行一段代码,但是不知道在stringgrid中应该使用那个事件?
我自己感觉是在onStringGrid1SelectCell中编写,可问题是我怎样判断我是按了左键select还是右键select呢?

解决方案 »

  1.   

    判断鼠标左右键在mouse的事件里面
    例如:
    procedure TForm1.StringGrid1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if Button=mbRight then//右键end;
      

  2.   

    procedure TForm1.StringGrid1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    var
      ACol,ARow:integer;
    begin
      if Button=mbRight  then    //右键按下
      begin
         StringGrid1.MouseToCell(X,Y,ACol,ARow);  //判断这时在哪个格子
         if Acol,ARow满足你的条件 then
         begin
         //做你想做的
         end;
      end;
    end;