Mega Code Archive

 
Categories / C# Tutorial / GUI Windows Forms
 

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());     }      }