本文实例讲述了C#及WPF获取本机所有字体和颜色的方法。分享给大家供大家参考。具体如下:
WPF 获取所有的字体:
1 2 3 4 5 6 | System.Drawing.Text.InstalledFontCollection font = new System.Drawing.Text.InstalledFontCollection(); System.Drawing.FontFamily[] array= font.Families; foreach (var v in array) { MessageBox.Show(v.Name); } |
WPF 获取所有的颜色:
1 2 3 4 5 6 | Type type = typeof (System.Windows.Media.Brushes); System.Reflection.PropertyInfo[] info = type.GetProperties(); foreach (System.Reflection.PropertyInfo pi in info) { string colorName=pi.Name; } |
C#获取所有的字体:
1 2 3 4 5 6 7 8 9 | InstalledFontCollection MyFont= new InstalledFontCollection(); FontFamily[] MyFontFamilies=MyFont.Families; ArrayList list = new ArrayList(); int Count=MyFontFamilies.Length; for ( int i=0;i <Count;i++) { string FontName=MyFontFamilies[i].Name; list.add(FontName); } |
C#获取所有的颜色:
1 2 3 4 5 | Array colors = System.Enum.GetValues( typeof (KnownColor) ); foreach ( object colorName in colors ){ ListItem tmp = new ListItem( colorName.ToString() , colorName.ToString()); this .styleColor.Items.Add( tmp ); } |
希望本文所述对大家的C#程序设计有所帮助。