How do I set button font to Marlett

10,711

Solution 1

Though I do not know what code is behind the designer, I have always found that custom installed fonts do not show up in the designer. The good news is that the Font property is ambient so if you wanted all controls to have the same Font you would only have to set it at the Form. However, it seems like you just want one control to have the Font so let's do this:

ctrl.Font = new Font("Marlett", 8.5f);

which will set that control's Font to Marlett and a size of 8.5 for example.

If you wanted an entire set of controls to have the same Font, if they can be placed in a container like a Panel, then you would only have to set the Font of the Panel; because again, it's an ambient property.

Solution 2

   button1.Font = new Font("Marlett",8, FontStyle.Regular);

put this code for your button name Button1 , where you want change ( in from constrcutor after iinitializecomponet or in form Load event )

Solution 3

It would seem that the designer by default wants to set the GdiCharSet to 0. This causes the Marlett font to fall back to another font.

If you change the GdiCharSet to 1 it will render normally.

Also note the changes it makes in the .designer.cs, this will also explain why it did work when you would set the font manually from code.

Solution 4

This is what finally worked for me.

ctrl.Font = new System.Drawing.Font("Marlett", 12f, FontStyle.Regular, GraphicsUnit.Point, ((byte)(1)));

The last ((byte)(1)) sets the GdiCharSet to 1, which @Paul noted in one of the other answers.

Share:
10,711
Spook
Author by

Spook

I develop software in C#, C++, Python, Javascript and couple more languages - depending on needs. My GitLab (since SO is biased towards GitHub for some reason): https://gitlab.com/spook/

Updated on June 24, 2022

Comments

  • Spook
    Spook almost 2 years

    I'm attempting to set a font of button to system's Marlett font. However, though I manually set the font-face, other font is used. Also, Marlett is not listed, when I use the font dialog to choose a font for that button.

    Why is it so? What can I do to use Marlett font in .NET Windows Forms controls?

  • Spook
    Spook about 11 years
    Marlett is a builtin font with glyphs like minimize, maximize, close, scrollbar arrows etc. Designer fails to set it properly (even if I force it to, manually entering the font name), but your solution from the code actually works. Thanks!
  • Mike Perrenoud
    Mike Perrenoud about 11 years
    @Spook, I'm really glad I could be of assistance!