1

I am building a simple app in Visual Studio 2013 for Windows 8 (a universal app), I want to change the font family of textbox using the selected font of combobox.

I know how to fill a combobox with available fonts in windows form app, like for example:

    List<string> fonts = new List<string>();

    foreach (FontFamily font in System.Drawing.FontFamily.Families)
    {
        fonts.Add(font.Name);
    }

but this is not working in metro/store app... please help me out

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dev
  • 78
  • 1
  • 13
  • 1
    What do you mean by _not working_? You get any exception or error message? Can you please be more specific? – Soner Gönül Apr 12 '15 at 11:05
  • am getting error on System.Drawing ....The type or namespace name 'Drawing' does not exist in the namespace 'System' – Dev Apr 12 '15 at 14:49

1 Answers1

1

You'll need to use DirectX DirectWrite to get the font names. Here is a code sample:

 using SharpDX.DirectWrite;
 using System.Collections.Generic;
 using System.Linq;

 namespace WebberCross.Helpers
 {
     public class FontHelper
     {
         public static IEnumerable<string> GetFontNames()
         {
             var fonts = new List<string>();

             // DirectWrite factory
             var factory = new Factory();

             // Get font collections
             var fc = factory.GetSystemFontCollection(false);

             for (int i = 0; i < fc.FontFamilyCount; i++)
             {
                 // Get font family and add first name
                 var ff = fc.GetFontFamily(i);

                 var name = ff.FamilyNames.GetString(0);
                 fonts.Add(name);
             }

             // Always dispose DirectX objects
             factory.Dispose();

             return fonts.OrderBy(f => f);
         }
     }
 }

The code uses SharpDX library.

Abhishek
  • 1,349
  • 8
  • 17