2

I've written this code:

List<string> fontNames = new List<string>();
foreach (FontFamily font in FontFamily.Families)
{
    fontNames.Add(font.Name);
}

to get fonts name, but lets say if you want to copy the font to another folder, how would I get the font's file name in order to do the copy operation?

Thank you.

11
  • Did you try using the BaseURI property? msdn.microsoft.com/en-us/library/… Commented Sep 13, 2011 at 20:29
  • I'm using .net 2. it's not supported...
    – Kourosh
    Commented Sep 13, 2011 at 20:31
  • @Xeon06 seems to be some WPF functionality. Being conservative, I would assume he is refering to WinForms only.
    – Uwe Keim
    Commented Sep 13, 2011 at 20:32
  • Then upgrade your .NET version. Commented Sep 13, 2011 at 20:32
  • I'm creating a class library to use in another application.
    – Kourosh
    Commented Sep 13, 2011 at 20:33

2 Answers 2

2

If you're able to access the registry, so you could get the file name out of the Key: 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', basically every font file is placed in C:\Windows\Fonts, unless mentioned elsewhere.

0
1

There is a C++ solution over at CP for getting a filename from a HFONT GDI+ font handle.

You could first use the Font.ToHfont() method to get the font handle and then use the code in the mentioned CP article. Of course this would require to rewrite the C++ code to C# with some PInvoke's.

Not the answer you're looking for? Browse other questions tagged or ask your own question.