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://blog.csdn.net/tiankun66/article/details/4616049

posted @ 2014-03-04 00:17  hanks  阅读(367)  评论(0)    收藏  举报