What's new
  • Howdy, Guest!

    We have issued a forced password reset on all user accounts, meaning you will not be able to login until this process is complete. Instructions will be displayed when you login with your previous credentials, however if for any reason you do not have access to your associated email address, you will need to contact us at [email protected].

    For more information, please read this Important Announcement

    Thank you for being awesome!

[C#] Embed Font Question (Not too long answer needed)

  • Thread starter trippinz
  • Start date
  • Views 1,950
trippinz

trippinz

Enthusiast
Programmer Grammar Nazi Frame In Gold
Messages
839
Reaction score
200
Points
175
Sin$
0
As of now I have placed the custom font in the "resources" folder and then called the font when I need to use it.

This allows the user not to be hassled by the fact that they need to manually download the font

Now, so far this works....on some computers but on other computers the font just shows up as boxes like -> []

The answer I am looking for is this:
-How do I properly embed the font

Please donot redirect me to another link as I am pretty sure I know which link it is and the program they use is really old. I use Visual Studio 2010 (C#)....

Even if you could help me through PM/AIM/MSN I will be really gratefull
 
SotG Caboose

SotG Caboose

Getting There
Messages
1,448
Reaction score
687
Points
230
Sin$
0
Are you using the Font class or a windows font file?
 
L

Lolzorz

Enthusiast
Messages
824
Reaction score
60
Points
135
Sin$
7
I think he's talking about how I gave him the Xbox font, but since most people don't have it, he wants it embedded into the program, so the text shows up for the preview.
 
Z

Zer0-One

Experienced Member
Messages
2,178
Reaction score
256
Points
220
Sin$
0
I'm not sure about this, but I'd copy the file over to their Fonts folder. If that doesn't work, then figure out another way to install the font using C#. Google it, and I'm sure you'd find a ton of info.
 
trippinz

trippinz

Enthusiast
Programmer Grammar Nazi Frame In Gold
Messages
839
Reaction score
200
Points
175
Sin$
0
It is the xbox font (ends in .ttf so its a true type font if thats any help)

How can I install it in the users font folder without showing them the actual font file and without triggering a virus alert ?
 
sgt frankieboy

sgt frankieboy

Enthusiast
Messages
722
Reaction score
140
Points
125
Sin$
7
maybe put it in your resources.

p.s. if you know the answer, please post it :smile: try to figure it out also, but currently I don't have Visual Studio
 
SotG Caboose

SotG Caboose

Getting There
Messages
1,448
Reaction score
687
Points
230
Sin$
0
^^ Add to your resources. During run time, copy the font to the windows font folder. When you exit the program, delete the font file that was copied.
 
L

Lolzorz

Enthusiast
Messages
824
Reaction score
60
Points
135
Sin$
7
On form load

if (File.Exists("C:\\Windows\\Fonts\\Convection.TTF")) {
} else {
File.WriteAllBytes("C:\\Windows\\Fonts\\", My.Resources.Convection.TTF);
}

On form close

if (File.Exists("C:\\Windows\\Fonts\\Convection.TTF")) {
} else {
File.Delete("C:\\Windows\\Fonts\\Convection.TTF");
}
That code will Write it, if it doesn't exist, and delete it if it doesn't exist, BUT will NOT delete it if they already have it.
 
SotG Caboose

SotG Caboose

Getting There
Messages
1,448
Reaction score
687
Points
230
Sin$
0
On form load

Code:
if (!File.Exists("C:\\Windows\\Fonts\\Convection.TTF"))
File.WriteAllBytes("C:\\Windows\\Fonts\\", My.Resources.Convection.TTF);

On form close

Code:
if (File.Exists("C:\\Windows\\Fonts\\Convection.TTF"))
File.Delete("C:\\Windows\\Fonts\\Convection.TTF");

fixed xD

also, "delete if it doesn't exist"? wtf. I think you mean, create it if it doesn't exist, and then delete it on exit if it does exist.
 
L

Lolzorz

Enthusiast
Messages
824
Reaction score
60
Points
135
Sin$
7
fixed xD

also, "delete if it doesn't exist"? wtf. I think you mean, create it if it doesn't exist, and then delete it on exit if it does exist.
If the font isn't there, it will send the font to the font folder. If it's not there, they more than likely won't want to have it, so it will delete it on form close.
If Convection is there - Font goes to folder. On form close - If it had to send the font over, it will delete it.
If Convection is already there - Nothing happens.
 
SotG Caboose

SotG Caboose

Getting There
Messages
1,448
Reaction score
687
Points
230
Sin$
0
If the font isn't there, it will send the font to the font folder. If it's not there, they more than likely won't want to have it, so it will delete it on form close.
If Convection is there - Font goes to folder. On form close - If it had to send the font over, it will delete it.
If Convection is already there - Nothing happens.
But he acted like he only wants the font there during run time, which is what my code does. Also, go learn how to make if statements.
 
L

Lolzorz

Enthusiast
Messages
824
Reaction score
60
Points
135
Sin$
7
But he acted like he only wants the font there during run time, which is what my code does. Also, go learn how to make if statements.
Ya, still learning C#, but you only had to make the delete function, it didn't have to check to see if it was there on form close. File.Delete("C:\\Windows\\Fonts\\Convection.TTF");
 
trippinz

trippinz

Enthusiast
Programmer Grammar Nazi Frame In Gold
Messages
839
Reaction score
200
Points
175
Sin$
0
A squiggly red line under File guys !!

edit: NVM- forgot to add
Code:
using System.IO;

Code:
if (!File.Exists("\\\\Windows\\Fonts\\XBOXTESTFONT.TTF"))
{
File.WriteAllBytes("\\\\Windows\\Fonts\\", WindowsFormsApplication1.Properties.Resources.XBOXTESTFONT);
}

File.WriteAllBytes("\\\\Windows\\Fonts\\", WindowsFormsApplication1.Properties.Resources.XBOXTESTFONT);

The network path was not found. !!!!!

Code:
            if (!File.Exists("\\\\Windows\\Fonts\\XBOXTESTFONT.TTF"))
{
File.WriteAllBytes("\\\\Windows\\Fonts\\", WindowsFormsApplication1.Properties.Resources.XBOXTESTFONT);
}

I get

The network path was not found.

at

File.WriteAllBytes("\\\\Windows\\Fonts\\", WindowsFormsApplication1.Properties.Resources.XBOXTESTFONT);
 
trippinz

trippinz

Enthusiast
Programmer Grammar Nazi Frame In Gold
Messages
839
Reaction score
200
Points
175
Sin$
0
I am going to do this last in my project, so I will get back to this topic soon
 
Top Bottom
Login
Register