delphi的stringgrid的drawcell事件的两个功能怎么协调?

来源:百度知道 编辑:UC知道 时间:2024/05/13 09:39:52
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
{ if not((acol=icol)and(arow>=stringgrid1.FixedRows))then //重画列颜色
exit;
with stringgrid1 do
begin
Canvas.Brush.Color:=mycolor;
Canvas.FillRect(rect);
Canvas.TextOut(rect.Left+2,rect.Top+2,stringgrid1.Cells[acol,arow]);
end; }

if not((arow=irow)and(acol>=stringgrid1.FixedCols))then //重画行颜色
exit;
with stringgrid1 do
begin
Canvas.Brush.Color:=mycolor;
Canvas.FillRect(rect);
Canvas.TextOut(rect.Left+2,rect.Top+2,stringgrid1.Cells[acol,arow]);
end;
end;

var
Form1: TForm1;
icol:integer;
irow:integer;//添加这个行序号变量
mycolor:TColor;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
i,j:integer;
begin
icol := -1;
mycolor := clwhite;
with stringgrid1 do
for i:=1 to colcount-1 do
for j:=1 to rowcount-1 do
begin
cells[i,0]:='第'+inttostr(i)+'列';
cells[0,j]:='第'+inttostr(j)+'行';
end;
end;

procedure TForm1.N2Click(Sender: TObject);
begin
icol:=stringgrid1.Col ;
mycolor:=clred;
irow := -1;//用于在drawcell中判断是画行还是画列
stringgrid1.Repaint ;
end;

procedure TForm1.N3Click(Sender: TObject);
begin
icol:=stringgrid1.Col ;
mycolor:=clblue;
irow := -1;//用于在drawcell中判断是画行还是画列
stringgrid1.Repaint ;
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button