List Fonts : FontFamilies « 2D Graphics « C# / C Sharp






List Fonts

 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {
    public Form1() {
        this.BackColor = Color.White;
    }
    protected override void OnPaint(PaintEventArgs e) {
        int verticalCoordinate = 10;
        Point topLeftCorner;
        InstalledFontCollection insFont = new InstalledFontCollection();
        FontFamily[] families = insFont.Families;
        e.Graphics.TranslateTransform(AutoScrollPosition.X,AutoScrollPosition.Y);
        foreach (FontFamily family in families) {
            if (family.IsStyleAvailable(FontStyle.Regular)) {
                Font f = new Font(family.Name, 10);
                topLeftCorner = new Point(10, verticalCoordinate);
                verticalCoordinate += f.Height;
                e.Graphics.DrawString(family.Name, f, Brushes.Black, topLeftCorner);
                f.Dispose();
            }
        }
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

 








Related examples in the same category

1.Write font metrics for Arial font family
2.Write font metrics for Courier New font family
3.Write font metrics for Times New Roman font family
4.FontFamilies: IsStyleAvailable,