delphi stringgrid 某单元格字体颜色
StringGrid1.Cells[1,2]:='1233';StringGrid1.Cells[2,2]:='1233';StringGrid1.Cells[2,4]:...
StringGrid1.Cells[1,2]:='1233';
StringGrid1.Cells[2,2]:='1233';
StringGrid1.Cells[2,4]:='1233';
我想让上面的字体加上红色的字。请高手解答。
sdl0819 是解决一半了。还有的问题是StringGrid1.Cells[1,2]:='1233';
StringGrid1.Cells[2,2]:='123322';
StringGrid1.Cells[2,4]:='1266633';
我要的是上面这样的情况了。我没有说明清楚 展开
StringGrid1.Cells[2,2]:='1233';
StringGrid1.Cells[2,4]:='1233';
我想让上面的字体加上红色的字。请高手解答。
sdl0819 是解决一半了。还有的问题是StringGrid1.Cells[1,2]:='1233';
StringGrid1.Cells[2,2]:='123322';
StringGrid1.Cells[2,4]:='1266633';
我要的是上面这样的情况了。我没有说明清楚 展开
1个回答
展开全部
完整的程序源码:
您拷贝就可以运行:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
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
if Cells[ACol,ARow] = '1233' then
begin
Canvas.Font.Color := clred; //字体颜色为红的
Canvas.Brush.color:=clMoneyGreen; //背景为 美元绿色
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol,ARow]);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with StringGrid1 do
begin
RowCount :=5;//设置5行
ColCount :=5;//设置5列
Cells[1,2]:='1233';
Cells[2,2]:='1233';
Cells[2,4]:='1233';
end;
end;
end.
-----------------------------------------------------
关键是DrawCell事件,在这个事件中可以设字体名、大小、颜色、字体装饰、cell背景画布等
---------------------------------------------------
您拷贝就可以运行:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
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
if Cells[ACol,ARow] = '1233' then
begin
Canvas.Font.Color := clred; //字体颜色为红的
Canvas.Brush.color:=clMoneyGreen; //背景为 美元绿色
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol,ARow]);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with StringGrid1 do
begin
RowCount :=5;//设置5行
ColCount :=5;//设置5列
Cells[1,2]:='1233';
Cells[2,2]:='1233';
Cells[2,4]:='1233';
end;
end;
end.
-----------------------------------------------------
关键是DrawCell事件,在这个事件中可以设字体名、大小、颜色、字体装饰、cell背景画布等
---------------------------------------------------
参考资料: 个人8年delphi编程
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询