我现在用到Stringgrid,希望能够在运行时候鼠标移动到一格时能显示出那一格的行列,就像showHint一样,只不过Hint的内容是当前我鼠标移动到的那格的行列,请问可以实现吗?

解决方案 »

  1.   

    procedure TForm1.StringGrid1Click(Sender: TObject);
    var
      c,r: Integer;
    begin
      c := StringGrid1.Col; {当前列}
      r := StringGrid1.Row; {当前行}
      StringGrid1.Cells[c,r] := Format('列:%d;行:%d', [c,r]);
    end;
      

  2.   


      StringGrid1.Col;//列
      StringGrid1.Row;//行
      

  3.   


    procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
      X, Y: Integer);
    var
      i,j,m,n,k,l:Integer;
    begin
      self.vg_cou:=self.vg_cou+1;
      self.Label2.Caption:='触发事件'+inttostr(self.vg_cou);
      m:=y div self.StringGrid1.DefaultRowHeight;
      n:=y mod self.StringGrid1.DefaultRowHeight;
      if n>0 then
        m:=m+1;
      self.Label1.Caption:='行号:'+inttostr(m);
      i:=self.StringGrid1.ColCount;
      k:=0;
      for j:=0 to i-1 do
      begin
        l:=k;
        k:=k+self.StringGrid1.ColWidths[j];
        if (x>l) and (x<k) then
        begin
          self.Label7.Caption:='列号:'+inttostr(j+1);
          Break;
        end;
      end;
    end;