【delphi开源代码栏目提醒】:网学会员在delphi开源代码频道为大家收集整理了FontGF.pas提供大家参考,希望对大家有所帮助!
unit FontGF;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
I, J: Integer;
begin
//设定网格的列数,使其等于
系统字体的数目
StringGrid1.ColCount := Screen.Fonts.Count + 1;
StringGrid1.ColWidths [0] := 50;
for I := 1 to Screen.Fonts.Count do
begin
// 设定第一行为字体的名称
StringGrid1.Cells [I, 0] := Screen.Fonts.Strings [I-1];
//计算需要的最大列数
StringGrid1.Canvas.Font.Name := StringGrid1.Cells [I, 0];
StringGrid1.Canvas.Font.Size := 32;
StringGrid1.ColWidths [I] :=
StringGrid1.Canvas.TextWidth ('AaBbYyZz');
end;
// 设定行数
StringGrid1.RowCount := 26;
for I := 1 to 25 do
begin
//在第一列写其所在的行数
StringGrid1.Cells [0, I] := IntToStr (I+7);
// 设定高度
StringGrid1.RowHeights [I] := 15 + I*2;
// 添加其他行默认的文字
for J := 1 to StringGrid1.ColCount do
StringGrid1.Cells [J, I] := 'AaBbYyZz'
end;
StringGrid1.RowHeights [0] := 25;
end;
procedure TForm1.StringGrid1DrawCell (Sender: TObject;
Col, Row: Integer; Rect: TRect; State: TGridDrawState);
begin
//选择字体
if (Col = 0) or (Row = 0) then
StringGrid1.Canvas.Font.Name := 'Arial'
else
StringGrid1.Canvas.Font.Name := StringGrid1.Cells [Col, 0];
// 设定字体的大小
if Row = 0 then
StringGrid1.Canvas.Font.Size := 14
else
StringGrid1.Canvas.Font.Size := Row + 7;
// 设定背景颜色
if gdSelected in State then
StringGrid1.Canvas.Brush.Color := clHighlight
else if gdFixed in State then
StringGrid1.Canvas.Brush.Color := clBtnFace
else
StringGrid1.Canvas.Brush.Color := clWindow;
// 输出文本
StringGrid1.Canvas.TextRect (Rect, Rect.Left, Rect.Top,
StringGrid1.Cells [Col, Row]);
// 设定焦点
if gdFocused in State then
StringGrid1.Canvas.DrawFocusRect (Rect);
end;
end.