Font Viewer : 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# / C Sharp » 2D Graphics » FontScreenshots 
Font Viewer
Font Viewer

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;

namespace FontViewer
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class FontViewer : System.Windows.Forms.Form
    {
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.ComboBox lstFonts;
        private System.Windows.Forms.StatusBar statusBar;
        private System.Windows.Forms.StatusBarPanel panel;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public FontViewer()
        {
            //
            // 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()
        {
//          System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FontViewer));
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.label1 = new System.Windows.Forms.Label();
            this.lstFonts = new System.Windows.Forms.ComboBox();
            this.statusBar = new System.Windows.Forms.StatusBar();
            this.panel = new System.Windows.Forms.StatusBarPanel();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.panel)).BeginInit();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left
                | System.Windows.Forms.AnchorStyles.Right);
            this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                    this.lstFonts,
                                                                                    this.label1});
            this.groupBox1.Location = new System.Drawing.Point(0, -4);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(63240);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(1216);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(8012);
            this.label1.TabIndex = 0;
            this.label1.Text = "Choose Font:";
            // 
            // lstFonts
            // 
            this.lstFonts.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.lstFonts.DropDownWidth = 340;
            this.lstFonts.Location = new System.Drawing.Point(10012);
            this.lstFonts.Name = "lstFonts";
            this.lstFonts.Size = new System.Drawing.Size(34021);
            this.lstFonts.TabIndex = 1;
            this.lstFonts.SelectedIndexChanged += new System.EventHandler(this.lstFonts_SelectedIndexChanged);
            // 
            // statusBar
            // 
            this.statusBar.Location = new System.Drawing.Point(0165);
            this.statusBar.Name = "statusBar";
            this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
                                                                                         this.panel});
            this.statusBar.ShowPanels = true;
            this.statusBar.Size = new System.Drawing.Size(63220);
            this.statusBar.TabIndex = 1;
            // 
            // panel
            // 
            this.panel.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
            this.panel.Width = 616;
            // 
            // FontViewer
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(514);
            this.ClientSize = new System.Drawing.Size(632185);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.statusBar,
                                                                          this.groupBox1});
            this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
//          this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "FontViewer";
            this.Text = "FontViewer";
            this.Load += new System.EventHandler(this.FontViewer_Load);
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.FontViewer_Paint);
            this.groupBox1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.panel)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

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

        private void FontViewer_Load(object sender, System.EventArgs e)
        {

            System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
            foreach (FontFamily family in fonts.Families)
            {
                lstFonts.Items.Add(family.Name);
            }

            RegistryKey rk;
            rk = Registry.LocalMachine.OpenSubKey("Software\\ProseTech\\FontViewer");
            if (rk != nullthis.Text += " - " + rk.GetValue("Customer");


        }

        private void FontViewer_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (lstFonts.Text != ""
            {
                try
                {
                    e.Graphics.DrawString(lstFonts.Text, new Font(lstFonts.Text, 50), Brushes.Black, 1050);
                    statusBar.Panels[0].Text = "";                                                                                                         
                }
                catch (Exception err)
                {
                    statusBar.Panels[0].Text = err.Message;
                }
            }
        }

        private void lstFonts_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (lstFonts.Text != ""this.Invalidate();
        }
    }
}


           
       
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.Smoothing FontsSmoothing Fonts
9.Font FamyliesFont Famylies
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.