Using Font from included exe resource

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ALIENQuake
Posts: 112
Last visit: Mon Jan 29, 2024 7:35 am
Has voted: 4 times

Using Font from included exe resource

Post by ALIENQuake »

Hi,

I would like to use my own font. I can add this font as executable resource. But how I can setup for eg:

Code: Select all

$labelButton_EXIT.Font = 'Franklin Gothic Demi Cond, 14.25pt'
to read font from executable resource?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Using Font from included exe resource

Post by jvierra »

Here is an article outlining how to add a font from a resource. To build that resource you would have to either modify the EXE or add a resource DLL and specify it in the manifest.

https://stackoverflow.com/questions/159 ... -resources
User avatar
ALIENQuake
Posts: 112
Last visit: Mon Jan 29, 2024 7:35 am
Has voted: 4 times

Re: Using Font from included exe resource

Post by ALIENQuake »

OK but how to use it with Powershell and SAPIEN Powershell Form Project?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Using Font from included exe resource

Post by jvierra »

What is an included EXE resource. You would prefer a DLL resource and use the Win32 API or Net classes that load a resource from a DLL. There are at least a dozen ways to do this. Search for "load font from resource" to find examples.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Using Font from included exe resource

Post by jvierra »

You can also load directly from a font file:

Code: Select all

$myfonts = [System.Drawing.Text.PrivateFontCollection]::new()
$myfonts.AddFontFile('C:\Windows\Fonts\GOTHICI.TTF')
$myfonts.Families[0]
or from memory:

Code: Select all

$myfonts = [System.Drawing.Text.PrivateFontCollection]::new()
$myfonts.AddMemoryFont($ptrToMemory,$length)
$myfonts.Families[0]
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked