首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-12-28 
TStringGrid选中某行时改变字颜色和背景色,支持鼠标右键goRangeSelect : false //不允许选择多行goRowS

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;

?

热点排行