VB.NET, C#, PowerShellを使用しているエンジニアのためのサイト。
基本的な使用方法から開発で役立つTipsまで幅広く取り扱っています。
インストール済みフォントをコンボボックスのアイテムにするサンプルを紹介します。
インストール済みフォントを取得するには、InstalledFontCollectionを使用することで簡単に行えます。
1)InstalledFontCollectionからFontFamilyを取得
2)取得したFontFamilyオブジェクトのNameプロパティにフォント名が格納されているので、For Eachで1つずつ取り出しながらコンボボックスに追加。
private void Form1_Load(object sender, EventArgs e) { //InstalledFontCollectionオブジェクトの取得 System.Drawing.Text.InstalledFontCollection InstalledFont = new System.Drawing.Text.InstalledFontCollection(); //インストール済みフォントを取得してコンボボックスに表示する FontFamily[] FontFamilies = InstalledFont.Families; foreach ( FontFamily f in FontFamilies ) comboBox1.Items.Add(f.Name); }