改变当前行的颜色
在StringGrid1.Options中要包含goRowSelect
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with StringGrid1 do
with Canvas do
begin
if (ARow=Row)and(ACol>=FixedCols) then
Brush.Color:=clRed
else
if (ARow>=FixedRows)and(ACol>=FixedCols) then Brush.Color:=clWhite;
FillRect(Rect);
end;
end;
end.