delphi开发实例:保存字体设置的方法
来源:互联网 发布:4个千兆sfp端口 编辑:程序博客网 时间:2024/05/19 16:33
记得一年前软件里面用到字体设置时,想把字体信息保存到配置文件里面都是把相应的属性分开来保存一下,这样一直使用,最近想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;
用记事本打开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;
- delphi开发实例:保存字体设置的方法
- Delphi中Label字体的设置
- iOS开发 字体的几种设置方法
- Delphi的多线程开发实例
- Delphi的多线程开发实例
- UIPickerView设置字体的方法
- IOS开发的字体样式的设置
- 设置TextView的字体颜色的方法
- MFC字体设置,实现字体旋转的方法
- android 开发 app全局字体的设置
- 【EditPlus】开发编辑器设置舒服的字体
- 使用IDISPLAY_SetColor设置字体颜色的方法
- eclipse字体颜色设置的方法
- eclipse字体颜色的设置方法
- ios设置navigationbar.title字体的方法
- 单个控件字体设置的方法
- eclipse字体颜色设置的方法
- eclipse字体颜色的设置方法
- 明天科目2要注意的地方
- 整数划分hdu 4651,hdu4658
- wordpress主题常用函数(二)
- java double 类型的怪现象
- 转载:CentOS如何给Firefox安装Flash插件
- delphi开发实例:保存字体设置的方法
- test
- 根据资源路径加载ZIP压缩包中指定的资源
- 填报表
- 常用个人密码管理软件
- 黑马程序员_自己写的DbHelper类库
- 常用js备用
- 分类:决策树—— Records of Questions
- response.write()不执行的解决办法