一个string问题 在string中如何让每行显示不同颜色 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果是一般的文本框,只需要改变.font.color就可以了! stringgrid 可以在 onDrawCell事件中自己画颜色 是StringGrid,单行显示如题头的灰色,双行白色 procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);var SGrdCount: TStringGrid; CellText: String; aTextLeft, aTextTop, aTextWidth, aTextHeight: Integer;begin SGrdCount := (Sender as TStringGrid); CellText := SGrdCount.Cells[ACol, ARow]; SGrdCount.Canvas.Font := SGrdCount.Font; //单行显示灰色 if(ARow Mod 2 = 0) then begin SGrdCount.Canvas.Brush.Color := SGrdCount.FixedColor; SGrdCount.Canvas.FillRect(Rect); Frame3D(SGrdCount.Canvas, Rect, clBtnHighlight, clBtnShadow, 1); end; //白色是默认色双行无需设置end; 数字也要画上去procedure TForm1.SGrdCountDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);var SGrdCount: TStringGrid; CellText: String; aTextLeft, aTextTop, aTextWidth, aTextHeight: Integer;begin SGrdCount := (Sender as TStringGrid); CellText := SGrdCount.Cells[ACol, ARow]; SGrdCount.Canvas.Font := SGrdCount.Font; //µ¥ÐÐÏÔʾ»ÒÉ« if(ARow Mod 2 = 0) then begin SGrdCount.Canvas.Brush.Color := SGrdCount.FixedColor; SGrdCount.Canvas.FillRect(Rect); Frame3D(SGrdCount.Canvas, Rect, clBtnHighlight, clBtnShadow, 1); end; //设置文字显示位置 aTextWidth := SGrdCount.Canvas.TextWidth(CellText); aTextHeight := SGrdCount.Canvas.TextHeight(CellText); aTextTop := Rect.Top + (Rect.Bottom - Rect.Top - aTextHeight) div 2; aTextLeft := Rect.Left + 2; SGrdCount.Canvas.TextRect(Rect, aTextLeft, aTextTop, CellText) ;end; 如何替换delphi的错误提示? 关于 ClientDataSet 的分析 如何判断窗体是从非活动窗体到活动窗体?急!! 如何在Delphi中实现单文档窗口 delphi 应用程序安装 delphi中Excel的UsedRange属性问题 关于opendatasource 的问题请教 条码打印 用Application.OnException如何对异常进行分类? StatusBar的错误? 进程状态问题 请问在Delphi中怎样转义&?
Rect: TRect; State: TGridDrawState);
var
SGrdCount: TStringGrid;
CellText: String;
aTextLeft, aTextTop, aTextWidth, aTextHeight: Integer;
begin
SGrdCount := (Sender as TStringGrid);
CellText := SGrdCount.Cells[ACol, ARow];
SGrdCount.Canvas.Font := SGrdCount.Font;
//单行显示灰色
if(ARow Mod 2 = 0) then
begin
SGrdCount.Canvas.Brush.Color := SGrdCount.FixedColor;
SGrdCount.Canvas.FillRect(Rect);
Frame3D(SGrdCount.Canvas, Rect, clBtnHighlight, clBtnShadow, 1);
end;
//白色是默认色双行无需设置
end;
procedure TForm1.SGrdCountDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
SGrdCount: TStringGrid;
CellText: String;
aTextLeft, aTextTop, aTextWidth, aTextHeight: Integer;
begin
SGrdCount := (Sender as TStringGrid);
CellText := SGrdCount.Cells[ACol, ARow];
SGrdCount.Canvas.Font := SGrdCount.Font;
//µ¥ÐÐÏÔʾ»ÒÉ«
if(ARow Mod 2 = 0) then
begin
SGrdCount.Canvas.Brush.Color := SGrdCount.FixedColor;
SGrdCount.Canvas.FillRect(Rect);
Frame3D(SGrdCount.Canvas, Rect, clBtnHighlight, clBtnShadow, 1);
end;
//设置文字显示位置
aTextWidth := SGrdCount.Canvas.TextWidth(CellText);
aTextHeight := SGrdCount.Canvas.TextHeight(CellText);
aTextTop := Rect.Top + (Rect.Bottom - Rect.Top - aTextHeight) div 2;
aTextLeft := Rect.Left + 2; SGrdCount.Canvas.TextRect(Rect, aTextLeft, aTextTop, CellText) ;
end;