Font list form : Font « GUI Windows Forms « C# / CSharp Tutorial






Font list form
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Text;
using System.Collections.Generic;

public class FontListForm : Form
{
    public FontListForm()
    {
        InitializeComponent();
    }

    private void FontListForm_Load(object sender, EventArgs e)
    {
        using (InstalledFontCollection fontFamilies = new InstalledFontCollection())
        {
            int offset = 10;
            foreach (FontFamily family in fontFamilies.Families)
            {
                try
                {
                    Label fontLabel = new Label();
                    fontLabel.Text = family.Name;
                    fontLabel.Font = new Font(family, 14);
                    fontLabel.Left = 10;
                    fontLabel.Width = pnlFonts.Width;
                    fontLabel.Top = offset;

                    pnlFonts.Controls.Add(fontLabel);
                    offset += 30;
                }catch{}
            }
        }
    }
    private System.ComponentModel.IContainer components = null;

    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    private void InitializeComponent()
    {
        this.pnlFonts = new System.Windows.Forms.Panel();
        this.SuspendLayout();

        this.pnlFonts.AutoScroll = true;
        this.pnlFonts.Dock = System.Windows.Forms.DockStyle.Fill;
        this.pnlFonts.Location = new System.Drawing.Point(0, 0);
        this.pnlFonts.Name = "pnlFonts";
        this.pnlFonts.Size = new System.Drawing.Size(299, 276);
        this.pnlFonts.TabIndex = 0;

        this.ClientSize = new System.Drawing.Size(299, 276);
        this.Controls.Add(this.pnlFonts);
        this.Name = "FontListForm";
        this.Text = "List of Installed Fonts";
        this.Load += new System.EventHandler(this.FontListForm_Load);
        this.ResumeLayout(false);

    }

    private System.Windows.Forms.Panel pnlFonts;
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new FontListForm());
    }
    
}








23.70.Font
23.70.1.Font Constructor: derive a fontFont Constructor: derive a font
23.70.2.RichTextBox: MultilineRichTextBox: Multiline
23.70.3.Create a font from font name and size
23.70.4.Create a font from FontFamilyCreate a font from FontFamily
23.70.5.Use GraphicsUnit to create fontUse GraphicsUnit to create font
23.70.6.List all Font FamiliesList all Font Families
23.70.7.Font PropertiesFont Properties
23.70.8.Font list formFont list form