怎么取得 fontdialog 的字体名称、大小等内容
把这些内容放在字符串里
kaida (2006-11-21 10:41:15)
procedure TForm1.Button1Click(Sender: TObject);
var
font:TFont;
begin
if FontDialog1.Execute then
begin
font:=FontDialog1.Font;
Memo1.Clear;
Memo1.Lines.Add('字体:'+Font.Name);
Memo1.Lines.Add('尺寸:'+Inttostr(Font.Size));
//......
end;
end;
张飞2002 (2006-11-21 10:54:11)
function FontToString( Font: TFont): string;
begin
with Font do
Result := Format('%.8x%.8x%.4x%.4x%.1x%.2x%.1x%.4x%s', [Color, Height, Size,
PixelsPerInch, Byte(Pitch), CharSet, Byte(Style), Length(Name), Name]);
end;
procedure StringToFont(var Str: string; Font: TFont);
var
Buff: string;
begin
if Length(Str) < 33 then exit;//raise Exception.Create('Error Font Format String');
Buff := Copy(Str, 1, 8);
Font.Color := StrToInt('$' + Buff);
Buff := Copy(Str, 9, 8);
Font.Height := StrToInt('$' + Buff);
Buff := Copy(Str, 17, 4);
Font.Size := StrToInt('$' + Buff);
Buff := Copy(Str, 21, 4);
Font.PixelsPerInch := StrToInt('$' + Buff);
Buff := Copy(Str, 25, 1);
Font.Pitch := TFontPitch(StrToInt('$' + Buff));
Buff := Copy(Str, 26, 2);
Font.Charset := TFontCharSet(StrToInt('$' + Buff));
Buff := Copy(Str, 28, 1);
Font.Style := TFontStyles(Byte(StrToInt('$' + Buff)));
Buff := Copy(Str, 29, 4);
Font.Name := Copy(Str, 33, StrToInt('$' + Buff));
end;