delphi保存字体设置

记得一年前软件里面用到字体设置时,想把字体信息保存到配置文件里面都是把相应的属性分开来保存一下,这样一直使用,最近想delphi自己的dfm文件也同样会保存这些信息,它又是怎样保存的呢。。

用记事本打开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;

 

转载于:https://www.cnblogs.com/delx/archive/2011/11/18/fonttostring.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值