我想在Stirnggrid中显示不同颜色的字体,
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin if StringGrid1.Cells [Acol,ARow]='3' then
StringGrid1.Canvas.font.Color :=clred;
if StringGrid1.Cells [Acol,ARow]='5' then
StringGrid1.Canvas.font.Color :=clblue;
if StringGrid1.Cells [Acol,ARow]='1' then
StringGrid1.Canvas.font.Color :=clblack;
end;可是并没有效果,但我写成:procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if StringGrid1.Cells [Acol,ARow]='3' then
StringGrid1.Canvas.brush.Color :=clred;
if StringGrid1.Cells [Acol,ARow]='5' then
StringGrid1.Canvas.brush.Color :=clblue;
if StringGrid1.Cells [Acol,ARow]='1' then
StringGrid1.Canvas.brush.Color :=clblack; StringGrid1.Canvas.FillRect (Rect)
end;
这样又可以?还有就是要是写成:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if StringGrid1.Cells [Acol,ARow]='3' then
StringGrid1.Font.Color :=clred;
if StringGrid1.Cells [Acol,ARow]='5' then
StringGrid1.Font.Color :=clblue;
if StringGrid1.Cells [Acol,ARow]='1' then
StringGrid1.Font.Color :=clblack;end; 屏幕会不停的闪烁.这是为什么?
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin if StringGrid1.Cells [Acol,ARow]='3' then
StringGrid1.Canvas.font.Color :=clred;
if StringGrid1.Cells [Acol,ARow]='5' then
StringGrid1.Canvas.font.Color :=clblue;
if StringGrid1.Cells [Acol,ARow]='1' then
StringGrid1.Canvas.font.Color :=clblack;
end;可是并没有效果,但我写成:procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if StringGrid1.Cells [Acol,ARow]='3' then
StringGrid1.Canvas.brush.Color :=clred;
if StringGrid1.Cells [Acol,ARow]='5' then
StringGrid1.Canvas.brush.Color :=clblue;
if StringGrid1.Cells [Acol,ARow]='1' then
StringGrid1.Canvas.brush.Color :=clblack; StringGrid1.Canvas.FillRect (Rect)
end;
这样又可以?还有就是要是写成:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if StringGrid1.Cells [Acol,ARow]='3' then
StringGrid1.Font.Color :=clred;
if StringGrid1.Cells [Acol,ARow]='5' then
StringGrid1.Font.Color :=clblue;
if StringGrid1.Cells [Acol,ARow]='1' then
StringGrid1.Font.Color :=clblack;end; 屏幕会不停的闪烁.这是为什么?
解决方案 »
- 求一个控件
- Delphi 菜单去掉快捷(如Z X Y)
- 用delphi对word操作进行评分(比对和分数设置问题)
- Access用SQL语句,出现charindex不能用
- delphi20005中面向對象的特性(比如命名空間),可以用在原生程序開發上麼?
- 原来的T2688手机不行了,想买个新的----1500上下 请大家推荐几款好用的、口碑好的手机好不好。 顺便散分廖表谢意!
- 数据精度比较问题!
- 关于delphi的json工具SuperObject问题
- 黨按下button時,模擬在edit1的按下回車鍵,怎麼實現?
- 请问(上,下,左,右,退格,回车)各键的ASCLL值?
- 请问怎么往固定WORD表格格式填充数据?
- 如何删除修改文本文件中的内容
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
StringGrid1.Canvas.FillRect (Rect);//清除以前的字体
if StringGrid1.Cells [Acol,ARow]='3' then
StringGrid1.Canvas.font.Color :=clred;
if StringGrid1.Cells [Acol,ARow]='5' then
StringGrid1.Canvas.font.Color :=clblue;
if StringGrid1.Cells [Acol,ARow]='1' then
StringGrid1.Canvas.font.Color :=clblack;
DrawText(StringGrid1.Canvas.Handle,
PChar(StringGrid1.Cells[ACol,ARow]),
Length(StringGrid1.Cells[ACol,ARow]),
DT_Left or DT_VCenter or DT_SingleLine);
//把新的字体画出来!!
end;//代码没有测试,你自己试吧,完善一下就可以了