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

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
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
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
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
w_w_w___._j_a___v_a___2_s__.__c__o_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.