Sign in to follow this  
Followers 0
E1M1

How to load font from file with out installing it.

3 posts in this topic

#1 ·  Posted (edited)

I am trying to load font from file because this way I dont have to install it (install requires admin rights but my program must be able to run nonadmin).

System.Drawing.Text.PrivateFontCollection privateFonts = new PrivateFontCollection();
privateFonts.AddFontFile("c:\myapplication\mycustomfont.ttf");
System.Drawing.Font font = new Font(privateFonts.Families[0], 12);
this.textBox1.Font = font;

AddFontFile (.NET) = AddFontResourceEx (API)

For some reason @error is 1. does anyone know what

has that function

$something = _WinAPI_AddFontResourceEx("File.tff")

but how translate rest of program to Autoit?

System.Drawing.Font font = new Font(privateFonts.Families[0], 12);
this.textBox1.Font = font;

My goal is to use that font with control I created with GUICtrlCreate*.

Thanks in advance.

Edited by E1M1

edited

Share this post


Link to post
Share on other sites



From WinAPIEx.au3:

#Include <StaticConstants.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

_WinAPI_AddFontResourceEx(@ScriptDir & '\Extras\SF Square Head Bold.ttf', $FR_PRIVATE)

GUICreate('MyGUI', 400, 100)
GUICtrlCreateLabel('Simple Text', 10, 25, 380, 50, $SS_CENTER)
GUICtrlSetFont(-1, 38, -1, -1, 'SF Square Head Bold')
GUICtrlSetColor(-1, 0xF06000)
GUISetState()

Do
Until GUIGetMsg() = -3

Do you mean something like this?

Br,

UEZ

1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

thank you. I didnt think it's that easy. C# has 3 lines to do what autoit does in 1 line :huh2:

I actually thought I need some API calls but it's that easy.

Exactly what I was looking for.

Edited by E1M1

edited

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0