如何 调用 字体文件变成资源文件 ?
如何字体文件变成资源文件, 调用它,这样即便系统里面没有该字体,也能在程序中显示。
请各位帮帮忙!
[解决办法]
1. Create RC file (e.g MY.RC)
MYFONT RCDATA "FONT_FILE_NAME"
2. Compile RC file using BRCC32 MY.RC
3. Add compiler directive {$R MY.RES}
4. Use below code in OnCreate and OnDestroy events
- Delphi(Pascal) code
procedure TForm1.FormCreate(Sender: TObject);var res: TResourceStream;begin res := TResourceStream.Create(hInstance, 'MYFONT', RT_RCDATA); try res.SavetoFile('myfont.ttf'); finally res.Free; end; AddFontResource(PChar('myfont.ttf')); SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0); //Now you use your own font Label1.Font.Size:=24; Label1.Font.Name:='myfont';end;//We don't want this font to be available after our application is closedprocedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ;begin RemoveFontResource('PATH_TO_MyFont.TTF') ; SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;end;
[解决办法]
Correction:
Remember Font's can be SHOULD be read as Font's CAN'T be
[解决办法]
It is working :). Please change the font of label1 at design time to something different like "Arial". Run the application and you will see font is changed to Trana.ttf font (Transponder AOE).
You will have to write the actual Font name instead of providing the ttf file name.
- Delphi(Pascal) code
Label1.Font.Size:=24; Label1.Font.Name:='Transponder AOE';