Font list : Font « GUI Windows Form « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » GUI Windows Form » FontScreenshots 
Font list
Font list

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace FontList
{
  /// <summary>
  /// Summary description for FontListForm.
  /// </summary>
  public class FontListForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.ListBox listBox1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public FontListForm()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();
      InitForm ();
      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    FontFamily [] fonts;
    protected void InitForm ()
    {
      fonts = FontFamily.Families;
      foreach (FontFamily font in fonts)
        listBox1.Items.Add (font.Name);
    }
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Disposebool disposing )
    {
      ifdisposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.listBox1 = new System.Windows.Forms.ListBox();
      this.SuspendLayout();
      // 
      // listBox1
      // 
      this.listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
      this.listBox1.Location = new System.Drawing.Point(2221);
      this.listBox1.Name = "listBox1";
      this.listBox1.Size = new System.Drawing.Size(226190);
      this.listBox1.TabIndex = 0;
      this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_OnDoubleClick);
      this.listBox1.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.listBox1_OnMeasureItem);
      this.listBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_OnDrawItem);
      this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_OnSelChanged);
      // 
      // FontListForm
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(266243);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.listBox1});
      this.Name = "FontListForm";
      this.Text = "Font Families";
      this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new FontListForm());
    }

    private void listBox1_OnDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
      Rectangle rc = e.Bounds;
      string strSample = "The quick red fox jumps over the lazy brown dog";
      Font fntText;
      Font fntSample;
      int cy = (rc.Bottom - rc.Top4;
      try
      {
        fntText = new Font ("Times New Roman"8, GraphicsUnit.Point);
      }
      catch (ArgumentException)
      {
        MessageBox.Show ("Cannot create Times New Roman font""Pied font",
          MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        return;
      }
      try
      {
        fntText = new Font ("Times New Roman"8, GraphicsUnit.Point);
        fntSample = new Font (fonts[e.Index]8, GraphicsUnit.Point);
      }
      catch (ArgumentException)
      {
        DialogResult mbResult = MessageBox.Show("Cannot open font " + fonts[e.Index].Name +"\nDo you want to delete this item from the list","Pied Font Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        switch (mbResult)
        {
          case DialogResult.Yes:
            listBox1.Items.RemoveAt (e.Index);
            return;
          case DialogResult.No:
            break;
        }
        strSample = "Cannot open font " + fonts[e.Index].Name;
        fntSample = fntText;
      }
      Brush brush;
      string str = fonts[e.Index].Name + " -- ";
      if ((e.State & DrawItemState.Selected!= 0)
      {
        e.Graphics.FillRectangle (Brushes.DarkBlue, rc);
        e.DrawFocusRectangle ();
        brush = Brushes.White;
      }
      else
      {
        e.Graphics.FillRectangle (Brushes.White, rc);
        brush = Brushes.Black;
      }
      e.Graphics.DrawString (str, fntText, brush, rc);
      StringFormat format = new StringFormat ();
      format.LineAlignment = StringAlignment.Center;
      format.FormatFlags = StringFormatFlags.LineLimit;
      SizeF size = e.Graphics.MeasureString (str, fntText);
      rc = new Rectangle (rc.Left + (int) (size.Width + .5),
        rc.Top, rc.Width, rc.Height);
      e.Graphics.DrawString (strSample, fntSample, brush, rc, format);
      fntText.Dispose ();
      fntSample.Dispose();
    }

    private void listBox1_OnSelChanged(object sender, System.EventArgs e)
    {
      listBox1.Invalidate ();
    }

    private void listBox1_OnMeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
    {
      MeasureItemEventArgs args = e;
      Font plain = new Font ("Times New Roman"10, GraphicsUnit.Point);
      SizeF size = e.Graphics.MeasureString ("Test", plain);
      args.ItemHeight = (int) (size.Height + .5);
      plain.Dispose ();
    }

    private void listBox1_OnDoubleClick(object sender, System.EventArgs e)
    {
      if (e is ListChangedEventArgs)
      {
        frmSampleText stuff = new frmSampleText ();
      }
    }
  }
  /// <summary>
  /// Summary description for frmSampleText.
  /// </summary>
  public class frmSampleText : System.Windows.Forms.Form
  {
    private System.Windows.Forms.TextBox textBox1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public frmSampleText()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Disposebool disposing )
    {
      ifdisposing )
      {
        if(components != null)
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.textBox1 = new System.Windows.Forms.TextBox();
      this.SuspendLayout();
      // 
      // textBox1
      // 
      this.textBox1.Location = new System.Drawing.Point(88);
      this.textBox1.Multiline = true;
      this.textBox1.Name = "textBox1";
      this.textBox1.Size = new System.Drawing.Size(272136);
      this.textBox1.TabIndex = 0;
      this.textBox1.Text = "textBox1";
      // 
      // frmSampleText
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(616);
      this.ClientSize = new System.Drawing.Size(296157);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.textBox1});
      this.Name = "frmSampleText";
      this.Text = "Sample Text";
      this.ResumeLayout(false);

    }
    #endregion
  }

}


           
       
Related examples in the same category
1. System Fonts: Icon Title FontSystem Fonts: Icon Title Font
2. Load all system installed fontsLoad all system installed fonts
3. Timer based animation for fontTimer based animation for font
4. Get all system installed fontGet all system installed font
w__ww___.___ja_v_a2s.___c__o__m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.