By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,053 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,053 IT Pros & Developers. It's quick & easy.

Use font stored in my application directory

P: n/a
Is it possible to use a font that is not stored in the windows font directory?

I would like to use a font that is stored in my application directory...

But this does not seem to work...

rtbMyRichTextBox.SelectionFont = New Font(CurDir() + "\" + "MyFont.ttf", 12,
FontStyle.Bold)

Thanks!

Bob
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

http://www.bobpowell.net/embedfonts.htm

Ken
------------------------

"BobAchgill" wrote:
Is it possible to use a font that is not stored in the windows font directory?

I would like to use a font that is stored in my application directory...

But this does not seem to work...

rtbMyRichTextBox.SelectionFont = New Font(CurDir() + "\" + "MyFont.ttf", 12,
FontStyle.Bold)

Thanks!

Bob

Nov 21 '05 #2

P: n/a
"BobAchgill" <Bo********@discussions.microsoft.com> schrieb:
Is it possible to use a font that is not stored in the windows font
directory?

I would like to use a font that is stored in my application directory...


Take a look at 'PrivateFontCollection.AddFontFile'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

P: n/a
I tried this but it does not seem to work... what am I missing?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim privateFontCollection As New PrivateFontCollection
privateFontCollection.AddFontFile(CurDir() + "\" + "radio___.ttf")
rtbMyRichTextBox.SelectionFont = New Font("radio", 12,
FontStyle.Regular)
rtbMyRichTextBox.SelectedText() = "write these words in Radio font
to My rich text box"
End Sub

"Herfried K. Wagner [MVP]" wrote:
"BobAchgill" <Bo********@discussions.microsoft.com> schrieb:
Is it possible to use a font that is not stored in the windows font
directory?

I would like to use a font that is stored in my application directory...


Take a look at 'PrivateFontCollection.AddFontFile'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

P: n/a
I used both your and Herfried's advice...

After I loaded the font in the private font collection using the code
Herfried suggested ...

privateFontCollection.AddFontFile(CurDir() + "\" + "radio___.ttf")

I tried to see if the font was actually there in the private collection by
running this code you suggested ...

' Get the array of FontFamily objects.
fontFamilies = privateFontCollection.Families

' How many objects in the fontFamilies array?
count = fontFamilies.Length

' Display the name of each font family in the private collection
' along with the available styles for that font family.
Dim j As Integer

While j < count
' Get the font family name.
familyName = fontFamilies(j).Name

End While
****************

I can see the fontFamily count go to 1 and the fontFamilies name shows up
correctly as Radio in autos during debug. This suggests that the font IS
getting loaded OK in the private font collection.

But for some reason, though, when I try to use the "Radio" font NOW stored
in the private font collection to write to the Rich Text Box there is a long
pause ... while i guess it is looking for the font and then instead the text
gets written using what appears to be a default font... because it cannot
find the "Radio" font??

When I change out the font in the write statement to a font I know is loaded
in the Windows Font directory that works OK and the text string gets written
in that font. But NOT when I try to use the private font.

I feel like I have traced this private font to the point where I should be
able to grad it with my bare hands but then it just disappears in thin air.

Hmmm???

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.