示例如下: procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin with Sender as TstringGrid do begin Canvas.Brush.Color := clyellow;//BackGround; Canvas.FillRect( stringgrid1.CellRect(1,1)); end; end;
兄弟不可以的, begin with Sender as TstringGrid do Canvas.Brush.Color := clyellow; Canvas.FillRect(stringgrid1.CellRect(1,1));
with Sender as TstringGrid do begin Canvas.Brush.Style := bsSolid; Canvas.Brush.Color := clyellow; Canvas.FillRect(stringgrid1.CellRect(1,1)); end;
with Sender as TstringGrid do begin Canvas.Brush.Style := bsSolid; if ((Sender as TStringGrid).Cells[ACol][ARow] = 'a') then Canvas.Brush.Color := clyellow else Canvas.Brush.Color := clRed; Canvas.FillRect(stringgrid1.CellRect(ACol,ARow)); end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin with StringGrid1 do begin if (ARow <= FixedRows - 1) or (ACol <= FixedCols - 1) then Canvas.Brush.Color := clBtnface else //根据不是的条件设置不同的颜色 Canvas.Brush.Color := ; Canvas.FillRect(Rect); end; end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with Sender as TstringGrid do
begin
Canvas.Brush.Color := clyellow;//BackGround;
Canvas.FillRect( stringgrid1.CellRect(1,1)); end;
end;
begin
with Sender as TstringGrid do
Canvas.Brush.Color := clyellow;
Canvas.FillRect(stringgrid1.CellRect(1,1));
只是给鼠表单击的单元边框加了红色,我要的是单元格的背景是红色的.
而且根据单元中内容不同背景色也要不同我的功能可以实现吗?
begin
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := clyellow;
Canvas.FillRect(stringgrid1.CellRect(1,1));
end;
begin
Canvas.Brush.Style := bsSolid;
if ((Sender as TStringGrid).Cells[ACol][ARow] = 'a') then
Canvas.Brush.Color := clyellow
else
Canvas.Brush.Color := clRed;
Canvas.FillRect(stringgrid1.CellRect(ACol,ARow));
end;
Rect: TRect; State: TGridDrawState);
begin
with StringGrid1 do
begin
if (ARow <= FixedRows - 1) or (ACol <= FixedCols - 1) then
Canvas.Brush.Color := clBtnface
else
//根据不是的条件设置不同的颜色
Canvas.Brush.Color := ;
Canvas.FillRect(Rect);
end;
end;