Ctrl_Alt_Defeat
Ctrl_Alt_Defeat

Reputation: 4009

C# - select system fonts from menu

I have developed a C# application - I want to now add a menu to it and have an option where the user can select which font they want which labels, etc will then be displayed in. So on my menu bar i added a Font and then the following in its method. I had read on net that this would work. However I am getting FontSelector/Fonts does not exist in current context. Is there a using directive i must add in order to get this too work and does anyone know what it is?

    private void SetFontToolStripMenuItem_Click(object sender, EventArgs e)
    {
        FontSelector.ItemsSource = Fonts.SystemFontFamilies;
    }

Upvotes: 0

Views: 3074

Answers (2)

Anders Forsgren
Anders Forsgren

Reputation: 11101

You can display this list in a combo box for example:

FontFamily[] fontList = new System.Drawing.Text.InstalledFontCollection().Families;

Upvotes: 0

Hinek
Hinek

Reputation: 9709

Why don't you use System.Windows.Forms.FontDialog? Saves you a lot of work ...

http://msdn.microsoft.com/en-us/library/system.windows.forms.fontdialog.aspx

It's a dialog form you can open, that enables the user to set a font family, size, color, etc. example:

FontDialog fontDialog1 = new FontDialog();
fontDialog1.Font = textBox1.Font;
fontDialog1.Color = textBox1.ForeColor;

if(fontDialog1.ShowDialog() != DialogResult.Cancel )
{
   textBox1.Font = fontDialog1.Font ;
   textBox1.ForeColor = fontDialog1.Color;
}

Upvotes: 6

Related Questions