TStringGrid选中某行时改变字颜色和背景色,支持鼠标右键

goRangeSelect := false ; //不允许选择多行

goRowSelect := true ; //选择行

procedure Tfm_main.Grid2DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
 s: String;
 R: TRect;
begin
  if ARow = Grid2.Row then
  begin
    TStringGrid(Sender).Canvas.Brush.Color := clmoneygreen;
    S := TStringGrid(Sender).Cells[ACol, ARow];
    R := TStringGrid(Sender).CellRect(ACol, ARow);
    TStringGrid(Sender).Canvas.FillRect(R);
    TStringGrid(Sender).Canvas.Font.Color := clTeal ;
    TStringGrid(Sender).Canvas.TextOut(R.Left, R.Top, S);
   end;
end;

 

procedure Tfm_main.Grid2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  Cell: TGridCoord;
begin
  try
    if (Button = mbRight) then
    begin
      Cell := Grid2.MouseCoord(X,Y);
      if (Cell.X >= 0) and (Cell.Y >= 1) then
      begin
        Grid2.Col := Cell.X;
        Grid2.Row := Cell.Y;
      end;
    end;
  except
  end;
end;

 

 

 

来自http://thinbug.bokele.com/?ArticleID=22454

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页