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;
}
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;
}
You can display this list in a combo box for example:
FontFamily[] fontList = new System.Drawing.Text.InstalledFontCollection().Families;
精彩评论