Font Famylies : Font « 2D Graphics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » 2D Graphics » FontScreenshots 
Font Famylies
Font Famylies

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Text; // InstalledFontCollection

namespace FontFamylies
{
    /// <summary>
    /// Summary description for FontFamylies.
    /// </summary>
    public class FontFamylies : System.Windows.Forms.Form
    {
        private System.Windows.Forms.ComboBox comboBox1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        FontFamily[] iFCF;
        ArrayList iFCFN;

        public FontFamylies()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            
            this.Text = "Installed Font Families";
            iFCF = null;                // fontfamilies
            iFCFN = new ArrayList();    // strings
            
            iFCF = InstalledFontFamilies(iFCFN);
            this.comboBox1.Sorted = true;
            this.comboBox1.DataSource = iFCFN;  //set the combo's data source

            //
            // 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.comboBox1 = new System.Windows.Forms.ComboBox();
            this.SuspendLayout();
            // 
            // comboBox1
            // 
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(12121);
            this.comboBox1.TabIndex = 0;
            this.comboBox1.Text = "comboBox1";
            // 
            // FontFamylies
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(513);
            this.ClientSize = new System.Drawing.Size(292266);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.comboBox1});
            this.Name = "FontFamylies";
            this.Text = "FontFamylies";
            this.ResumeLayout(false);

        }
        #endregion

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

        private FontFamily[] InstalledFontFamilies(ArrayList iFCFN)
        {
            InstalledFontCollection iFC = new InstalledFontCollection();
            foreach(FontFamily ff in iFC.Families)
                iFCFN.Add(ff.Name);
            return iFC.Families;
        }
        protected override void OnPaint(PaintEventArgs pea)
        {
            Graphics g = pea.Graphics;
            int wi = 150, hi = 12, rectNb = 4;
            this.Width = (wi + 2)*rectNb + 9;
            int iFCFNb = iFCF.Length;
            DisplayInstalledFontFamilies(g, iFCFNb, wi, hi, rectNb);

            g.Dispose();
        }
        private void DisplayInstalledFontFamilies(Graphics g, int iFCFNb, int wi,
            int hi, int rectNb)
        {
            Rectangle rec;
            Pen p = new Pen(this.ForeColor);
            Brush b = null;

            Font f;
            StringFormat strfmt = new StringFormat();
            strfmt.LineAlignment = strfmt.Alignment = StringAlignment.Near;

            int x, y;
            for (int i = 0; i < iFCFNb; i++)
            {
                x = (int)(i % rectNb);
                y = (int)(i / rectNb);
                rec = new Rectangle(+ x*(+ wi)25 + y*(+ hi), wi, hi);
                g.DrawRectangle(p, rec);

                try
                {
                    f = new Font(iFCF[i]8, FontStyle.Regular, GraphicsUnit.Point);
                }
                catch
                {
                    // some fonts do not support Regular style
                    f = new Font("Arial"8, FontStyle.Strikeout, GraphicsUnit.Point);
                }

                b  = new SolidBrush(Color.Black);
                g.DrawString((string)iFCFN[i], f, b, rec, strfmt);
            }

            p.Dispose();    b.Dispose();
        }
    }
}

           
       
Related examples in the same category
1.Draw font cell ascent, cell descent, line space, em height
2.Get font family infoGet font family info
3.Get font from Font dialog and redraw stringGet font from Font dialog and redraw string
4.Font size, name and strike outFont size, name and strike out
5.Font AttributesFont Attributes
6.Fonts ClassFonts Class
7.Font Metrics
8.Font ViewerFont Viewer
9.Smoothing FontsSmoothing Fonts
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.