線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1621
推到 Plurk!
推到 Facebook!

Font 如何存起來?

答題得分者是:zhouying82
alvin26
初階會員


發表:24
回覆:41
積分:28
註冊:2005-04-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-01-11 16:41:58 IP:61.63.xxx.xxx 訂閱
請問各位大大,
Font 要如何存起來呢?
例如有一個 memo , 我設完它的 font 後,
下次 application 再開起來的時候,
就自動載入上次設好的 Font.
想了半天一直沒有頭緒,
曾想過用 MemoryStream ,
但不知道有什麼方法可以把 Font Convert 成 二進位格式。
或是有其他更好的方法呢?
感謝~
------
弟子規,聖人訓,首孝悌,次謹信,泛愛眾,而親仁,有餘力,則學文。
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-01-11 20:59:23 IP:58.35.xxx.xxx 訂閱
可以用INI文件形式啊
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-01-11 21:25:45 IP:58.35.xxx.xxx 訂閱

[code delphi]

[code cpp]
var filedir:string; ini:Tinifile; MStyles:TFontStyles; MStylespoint:pointer; const MColor='Color'; MFontName='FontName'; MFontSize='Size'; MFontColor='FontColor'; MFontStyle='FontStyle'; procedure TForm1.FormCreate(Sender: TObject); //取执行文件目录 begin getdir(0,filedir); end; procedure TForm1.Button1Click(Sender: TObject); //写 begin ColorDialog1.Execute; with Memo1 do begin Color:=ColorDialog1.Color; end; FontDialog1.Execute; with Memo1 do begin Font:=FontDialog1.Font; end; Ini:=TIniFile.Create(filedir '\Font_Color.ini'); with Memo1 do begin Ini.WriteInteger(name,MColor,Color); Ini.WriteString(name,MFontName,Font.Name); Ini.WriteInteger(name,MFontSize,Font.Size); Ini.WriteInteger(name,MFontColor,Font.Color); MStyles:=Font.Style; MStylespoint:=@MStyles; Ini.WriteInteger(name,MFontStyle,integer(MStylespoint^)); end; Ini.Free; end; procedure TForm1.Button2Click(Sender: TObject); // 写 var a:integer; begin Ini:=TIniFile.Create(filedir '\Font_Color.ini'); try with Memo1 do begin Color:=Ini.ReadInteger(name,MColor,Color); Font.Name:=Ini.ReadString(name,MFontName,Font.Name); Font.Size:=Ini.ReadInteger(name,MFontSize,Font.Size); Font.Color:=Ini.ReadInteger(name,MFontColor,Font.Color); a:=Ini.ReadInteger(name,MFontStyle,0); MStylespoint:=@a; Font.Style:=TFontStyles(MStylespoint^); end; finally end; Ini.Free; end;
[/code]

[/code]

[code cpp]
var filedir:string; ini:Tinifile; MStyles:TFontStyles; MStylespoint:pointer; const MColor='Color'; MFontName='FontName'; MFontSize='Size'; MFontColor='FontColor'; MFontStyle='FontStyle'; procedure TForm1.FormCreate(Sender: TObject); //取执行文件目录 begin getdir(0,filedir); end; procedure TForm1.Button1Click(Sender: TObject); //写 begin ColorDialog1.Execute; with Memo1 do begin Color:=ColorDialog1.Color; end; FontDialog1.Execute; with Memo1 do begin Font:=FontDialog1.Font; end; Ini:=TIniFile.Create(filedir '\Font_Color.ini'); with Memo1 do begin Ini.WriteInteger(name,MColor,Color); Ini.WriteString(name,MFontName,Font.Name); Ini.WriteInteger(name,MFontSize,Font.Size); Ini.WriteInteger(name,MFontColor,Font.Color); MStyles:=Font.Style; MStylespoint:=@MStyles; Ini.WriteInteger(name,MFontStyle,integer(MStylespoint^)); end; Ini.Free; end; procedure TForm1.Button2Click(Sender: TObject); // 写 var a:integer; begin Ini:=TIniFile.Create(filedir '\Font_Color.ini'); try with Memo1 do begin Color:=Ini.ReadInteger(name,MColor,Color); Font.Name:=Ini.ReadString(name,MFontName,Font.Name); Font.Size:=Ini.ReadInteger(name,MFontSize,Font.Size); Font.Color:=Ini.ReadInteger(name,MFontColor,Font.Color); a:=Ini.ReadInteger(name,MFontStyle,0); MStylespoint:=@a; Font.Style:=TFontStyles(MStylespoint^); end; finally end; Ini.Free; end;
[/code]
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
編輯記錄
zhouying82 重新編輯於 2008-01-11 21:33:45, 註解 無‧
zhouying82 重新編輯於 2008-01-11 21:34:12, 註解 無‧
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-01-12 20:14:35 IP:222.64.xxx.xxx 訂閱
TFontRecall类试试
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-01-16 15:14:49 IP:122.127.xxx.xxx 訂閱

[code delphi]
procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Font.Name := '新細明體';
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var fontname:string;
begin
fontname := memo1.Font.Name;
end;

[/code]
------
努力會更接近成功
chkkevin
一般會員


發表:34
回覆:64
積分:19
註冊:2007-05-17

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-01-16 23:26:08 IP:218.254.xxx.xxx 訂閱
他的問題像是,把programe關掉之後,再開也能夠用回之前的font格式,
好像除了用ini方法之外便沒有了?
------
獨學無友則孤陋寡聞,相識滿天下能知天下事
小弟是來自香港的~~多多指教
alvin26
初階會員


發表:24
回覆:41
積分:28
註冊:2005-04-12

發送簡訊給我
#7 引用回覆 回覆 發表時間:2008-01-17 09:16:49 IP:219.87.xxx.xxx 訂閱
我知道了,謝謝 zhouying82 大大!! 感恩~

------
弟子規,聖人訓,首孝悌,次謹信,泛愛眾,而親仁,有餘力,則學文。
系統時間:2024-03-28 18:07:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!