××××××××××如何改变stringgrid里某个区域字体的颜色××××××××××

LWWL 2002-08-30 12:36:32
紧急
...全文
108 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
blazingfire 2002-08-30
  • 打赏
  • 举报
回复
写StringGrid的OnDrawCell事件:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
Txt:String;
begin
if (ACol=1) and (ARow=2) then
begin
Txt:=StringGrid1.Cells[ACol,ARow];
StringGrid1.Canvas.Font.Color:=clred;
StringGrid1.Canvas.Brush.Color:=clyellow;
StringGrid1.Canvas.Rectangle(Rect);
DrawText(StringGrid1.Canvas.Handle,
PChar(Txt),
Length(Txt),
Rect,
DT_Center or DT_VCenter or DT_SingleLine
);
end;
end;
netlib 2002-08-30
  • 打赏
  • 举报
回复
例:
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
if (acol=1) and (arow=2) then
begin
StringGrid1.Canvas.Font.Color:=clred;
StringGrid1.Canvas.Brush.Color:=clyellow;
StringGrid1.Canvas.TextRect(Rect,Rect.Left,Rect.Top,StringGrid1.Cells[Acol,arow]);
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
i,j : integer;
begin
StringGrid1.RowCount:=5;
StringGrid1.ColCount:=5;
for i:=0 to 4 do
for j:= 0 to 4 do
StringGrid1.Cells[i,j]:=inttostr(i*j);
end;

end.

5,939

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧