skip to Main Content

How can I change the font of my project in a way that anyone who downloads the app sees it with the font that I choose?

I’m using C#, Microsoft Visual Studio Code, Winforms.

I keep searching but all that I can find is a tutorial on how to install the font on my own computer.

2

Answers


  1. If you want to change the font of all controls in a form (.NET Framework). See this link.

    But, if you are using .NET Core (.NET 6 or later) you can:

    In project file inside <PropertyGroup> add:

    <ApplicationDefaultFont>Curlz MT, 18pt</ApplicationDefaultFont>
    

    You can also call Application.SetDefaultFont() directly in your Main() method as shown here:

    static void Main()
    {
        ApplicationConfiguration.Initialize();
    
        Application.SetDefaultFont(new Font(new FontFamily("Curlz MT"), 18f));
    
        Application.Run(new AirQualityForm());
    }
    
    Login or Signup to reply.
  2. Here is an example of a custom font working.

    (Important: In this example I dragged "FiraCode-SemiBold.ttf" into the root of my project, then I right clicked it in visual studio and set the property: "Copy to Output Directory" to "Copy if newer" (copy always will work too))

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
    
        var pfc = new PrivateFontCollection();
        pfc.AddFontFile("FiraCode-SemiBold.ttf");
        FontFamily fontFamily = pfc.Families[0];
        float fontSize = 8.25f;
        FontStyle fontStyle = FontStyle.Regular;
        GraphicsUnit graphicsUnit = GraphicsUnit.Point;
        byte gdiCharSet = 1;
    
        Application.VisualStyleState = System.Windows.Forms.VisualStyles.VisualStyleState.NoneEnabled;
        Application.SetDefaultFont(new Font(fontFamily, fontSize, fontStyle, graphicsUnit, gdiCharSet));
    
        Application.Run(new Form1());
    }
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search