Get font from Font dialog and redraw string : 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.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.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » 2D Graphics » FontScreenshots 
Get font from Font dialog and redraw string
Get font from Font dialog and redraw string


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

  public class Form1 : System.Windows.Forms.Form
  {
    private System.ComponentModel.Container components;
    private System.Windows.Forms.FontDialog fontDlg;
    private Font currFont;

    public Form1()
    {
      InitializeComponent();
      CenterToScreen();
      fontDlg = new System.Windows.Forms.FontDialog();    
      fontDlg.ShowHelp = true;    
      Text = "Click on me to change the font";
      currFont = new Font("Times New Roman"12);
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(292273);
      this.Text = "Form1";
      this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);

    }

    static void Main() 
    {
      Application.Run(new Form1());
    }

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
      Graphics g = e.Graphics;
      g.DrawString("www.java2java.com...", currFont, 
        new SolidBrush(Color.Black)00);  
    }

    private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      if (fontDlg.ShowDialog() != DialogResult.Cancel)
      {
        currFont = fontDlg.Font;
        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.Font size, name and strike outFont size, name and strike out
4.Font AttributesFont Attributes
5.Fonts ClassFonts Class
6.Font Metrics
7.Font ViewerFont Viewer
8.Smoothing FontsSmoothing Fonts
9.Font FamyliesFont Famylies
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.