http://blog.csdn.net/delphi308/article/details/9906147
delphi开发实例:保存字体设置的方法
用记事本打开dfm文件会看到类似这样的文本:
object Label1: TLabel
Left = 24
Top = 32
Width = 140
Height = 46
Caption = #20445#23384#23454#20363
Font.Charset = GB2312_CHARSET
Font.Color = clBlue
Font.Height = -35
Font.Name = #24494#36719#38597#40657
Font.Style = [fsBold, fsUnderline, fsStrikeOut]
ParentFont = False
end
自己写了个直接保存成文件文件的,记录一下
unit Font2String;
interface
uses
Classes, SysUtils, Dialogs, Graphics;
function Font2File(AFont: TFont; APath: string): Boolean;
function File2Font(APath: string; AFont: TFont): Boolean;
implementation
function Font2File(AFont: TFont; APath: string): Boolean;
var
FD: TFontDialog;
begin
Result := False;
FD := TFontDialog.Create(nil);
try
FD.Font.Assign(AFont);
WriteComponentResFile(APath, FD);
Result := True;
finally
FD.Free;
end;
end;
function File2Font(APath: string; AFont: TFont): Boolean;
var
FD: TFontDialog;
begin
Result := False;
FD := TFontDialog.Create(nil);
try
ReadComponentResFile(APath, FD);//如果此外为nil,下面的注册去掉
AFont.Assign(FD.Font);
Result := True;
finally
FD.Free;
end;
end;
//initialization
//RegisterClass(TFontDialog);
end.
例子:
procedure TForm1.Button1Click(Sender: TObject);
begin
Font2File(Label1.Font, 'd:\Font.fnt');//把字体保存成文件
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
File2Font( 'd:\Font.fnt', Label2.Font);//从文件里读取字体
end;