How to use a custom font

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi !

I wonder how I can change the font of a .NET C# application ? I have a
".ttf", I suppose it's a TrueType font file. I will appreciate any help, if
you have tutorials it will be great too.

Should I copy it to Windows System folder ?

Thanks in advance,

Regards.

Sadi.
 
Hi Sadi,

Are you trying to change the font of a windows form?

Or are you trying to install a ttf file and set that as the font for your
windows form?

Regards,
Rakesh Rajan
 
Hi Rakesh,

In fact my application will run under WinCE 5.0.

I want to display some part of text (using the .DrawString() method) with a
font file "filename.ttf". I am currently emulating my application with the
WinCE emulator.

1] I have installed this font in my desktop windows font dir.
I tried to use the font with this :It don't work. I think the problem is that the font file is not installed in
the emulator.

2] That's why I have attached the file to my project as an embedded ressource.
I have seen that with GDI+ I can specify the location of the font with
PrivateFontCollection. But I get an error when I type this :
"The type or namespace name 'PrivateFontCollection' could not be found (are
you missing a using directive or an assembly reference?)"

I don't know what else to do.

Regards.
Sadi.
 
Hi Sadi,

I am not sure about WinCE, but using the PrivateFontCollection is indeed the
way to use a font which our own app comes with. Specifically, you could use
the AddFontFile method of the class to accomplish this. Check out this
article in MSDN
http://msdn.microsoft.com/library/d...ating_a_private_font_collection_usecsharp.asp

Have you added the using directive to the System.Drawing.Text namespace?
This could be reason why the problem is caused.

HTH,
Rakesh Rajan

Sadi said:
Hi Rakesh,

In fact my application will run under WinCE 5.0.

I want to display some part of text (using the .DrawString() method) with a
font file "filename.ttf". I am currently emulating my application with the
WinCE emulator.

1] I have installed this font in my desktop windows font dir.
I tried to use the font with this :It don't work. I think the problem is that the font file is not installed in
the emulator.

2] That's why I have attached the file to my project as an embedded ressource.
I have seen that with GDI+ I can specify the location of the font with
PrivateFontCollection. But I get an error when I type this :
"The type or namespace name 'PrivateFontCollection' could not be found (are
you missing a using directive or an assembly reference?)"

I don't know what else to do.

Regards.
Sadi.

Rakesh Rajan said:
Hi Sadi,

Are you trying to change the font of a windows form?

Or are you trying to install a ttf file and set that as the font for your
windows form?

Regards,
Rakesh Rajan
 
Hi Rakesh,

The problem came from .NET compact framework, I am not sure that it support
the System.Drawing.Text.dll. I cannnot add an assembly reference to this
library. I will try to get confirmation in .NET Compact Framework neewsgroup.

Regards.

Sadi.

Rakesh Rajan said:
Hi Sadi,

I am not sure about WinCE, but using the PrivateFontCollection is indeed the
way to use a font which our own app comes with. Specifically, you could use
the AddFontFile method of the class to accomplish this. Check out this
article in MSDN:
http://msdn.microsoft.com/library/d...ating_a_private_font_collection_usecsharp.asp

Have you added the using directive to the System.Drawing.Text namespace?
This could be reason why the problem is caused.

HTH,
Rakesh Rajan

Sadi said:
Hi Rakesh,

In fact my application will run under WinCE 5.0.

I want to display some part of text (using the .DrawString() method) with a
font file "filename.ttf". I am currently emulating my application with the
WinCE emulator.

1] I have installed this font in my desktop windows font dir.
I tried to use the font with this :
Font fontfilename = new Font("filename",12,FontStyle.Regular);
It don't work. I think the problem is that the font file is not installed in
the emulator.

2] That's why I have attached the file to my project as an embedded ressource.
I have seen that with GDI+ I can specify the location of the font with
PrivateFontCollection. But I get an error when I type this :
PrivateFontCollection privateFontCollection = new PrivateFontCollection();

"The type or namespace name 'PrivateFontCollection' could not be found (are
you missing a using directive or an assembly reference?)"

I don't know what else to do.

Regards.
Sadi.

Rakesh Rajan said:
Hi Sadi,

Are you trying to change the font of a windows form?

Or are you trying to install a ttf file and set that as the font for your
windows form?

Regards,
Rakesh Rajan


:

Hi !

I wonder how I can change the font of a .NET C# application ? I have a
".ttf", I suppose it's a TrueType font file. I will appreciate any help, if
you have tutorials it will be great too.

Should I copy it to Windows System folder ?

Thanks in advance,

Regards.

Sadi.
 
I have not received an answer from the .NET Compact framework neewsgroup, I
am quite sure that System.Drawing.Text is not available.

Does anyone have an idea to use custom font without System.Drawing.Text
PrivateFontCollection

Thanks in advance,
Regards.

Sadi
 
Back
Top