UI Print : Print « GUI Windows Form « 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 » GUI Windows Form » PrintScreenshots 
UI Print
UI Print

/*
GDI+ Programming in C# and VB .NET
by Nick Symmonds

Publisher: Apress
ISBN: 159059035X
*/
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace UIPrint_c
{
    public class UIPrint : System.Windows.Forms.Form
    {
    private PrintPreviewDialog Pv;
    private PageSetupDialog Ps;
    private PrintDocument Pd;
    private PrintDialog Pr;

    private System.Windows.Forms.MainMenu mainMenu1;
    private System.Windows.Forms.MenuItem mnuFile;
    private System.Windows.Forms.MenuItem mnuSetup;
    private System.Windows.Forms.MenuItem mnuPreview;
    private System.Windows.Forms.MenuItem mnuPrint;
    private System.Windows.Forms.Button cmdQuit;



        private System.ComponentModel.Container components = null;

        public UIPrint()
        {
            InitializeComponent();

      Pv = new PrintPreviewDialog();
      Ps = new PageSetupDialog();
      Pr = new PrintDialog();
      Pd = new PrintDocument();

      Pd.DocumentName = "My New Document";
      Pv.Document = Pd;
      Ps.Document = Pd;
      Pr.Document = Pd;
        }

        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.mainMenu1 = new System.Windows.Forms.MainMenu();
      this.mnuFile = new System.Windows.Forms.MenuItem();
      this.mnuSetup = new System.Windows.Forms.MenuItem();
      this.mnuPreview = new System.Windows.Forms.MenuItem();
      this.mnuPrint = new System.Windows.Forms.MenuItem();
      this.cmdQuit = new System.Windows.Forms.Button();
      this.SuspendLayout();
      // 
      // mainMenu1
      // 
      this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                              this.mnuFile});
      // 
      // mnuFile
      // 
      this.mnuFile.Index = 0;
      this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                            this.mnuSetup,
                                                                            this.mnuPreview,
                                                                            this.mnuPrint});
      this.mnuFile.Text = "File";
      // 
      // mnuSetup
      // 
      this.mnuSetup.Index = 0;
      this.mnuSetup.Text = "Page Setup";
      this.mnuSetup.Click += new System.EventHandler(this.mnuSetup_Click);
      // 
      // mnuPreview
      // 
      this.mnuPreview.Index = 1;
      this.mnuPreview.Text = "Print Preview";
      this.mnuPreview.Click += new System.EventHandler(this.mnuPreview_Click);
      // 
      // mnuPrint
      // 
      this.mnuPrint.Index = 2;
      this.mnuPrint.Text = "Print";
      this.mnuPrint.Click += new System.EventHandler(this.mnuPrint_Click);
      // 
      // cmdQuit
      // 
      this.cmdQuit.Location = new System.Drawing.Point(256256);
      this.cmdQuit.Name = "cmdQuit";
      this.cmdQuit.Size = new System.Drawing.Size(6432);
      this.cmdQuit.TabIndex = 0;
      this.cmdQuit.Text = "Quit";
      this.cmdQuit.Click += new System.EventHandler(this.cmdQuit_Click);
      // 
      // UIPrint
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(342303);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.cmdQuit});
      this.MaximizeBox = false;
      this.Menu = this.mainMenu1;
      this.MinimizeBox = false;
      this.Name = "UIPrint";
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
      this.Text = "UIPrint";
      this.Load += new System.EventHandler(this.UIPrint_Load);
      this.ResumeLayout(false);

    }
        #endregion

        [STAThread]
        static void Main() 
        {
            Application.Run(new UIPrint());
        }

    private void UIPrint_Load(object sender, System.EventArgs e)
    {
      Pd.PrintPage += new PrintPageEventHandler(this.pd_Print);
    }

    protected override void OnPaint(PaintEventArgs e)
    {
      DrawIt(e.Graphics);
    }

    private void DrawIt(Graphics G)
    {
      G.SmoothingMode = SmoothingMode.AntiAlias;
      Pen P1 = new Pen(Brushes.Violet, 5);
      
      G.DrawString("Test of Print dialog and page setup",
                    new Font("Time New Roman"16),
                    Brushes.Blue,
                    new Point(55));
      G.DrawPie(P1, 10101501502857);
      G.FillEllipse(Brushes.BurlyWood, 10200this.Width-5050);
    }

    private void pd_Print(object sender, PrintPageEventArgs e)
    {
      DrawIt(e.Graphics);
    }

    private void mnuSetup_Click(object sender, System.EventArgs e)
    {
      Ps.ShowDialog();
      Pd.DefaultPageSettings = Ps.PageSettings;
      Pd.PrinterSettings = Ps.PrinterSettings;
    }

    private void mnuPreview_Click(object sender, System.EventArgs e)
    {
      Pv.WindowState = FormWindowState.Maximized;
      Pv.ShowDialog();
    }

    private void mnuPrint_Click(object sender, System.EventArgs e)
    {
      if (Pr.ShowDialog() == DialogResult.OK)
        Pd.Print();
    }

    private void cmdQuit_Click(object sender, System.EventArgs e)
    {
      this.Dispose();
    }

    }
}



           
       
Related examples in the same category
1.Control PrintControl Print
2.Simple Report PrinterSimple Report Printer
3.Begin Print
4.Define Print SettingsDefine Print Settings
5.Print Dialogs
6.Print EventsPrint Events
7.Basic Printing
8.Grid PrintingGrid Printing
9.Printer Caps 1
10.Printer Caps 2Printer Caps 2
11.Printer Caps 3Printer Caps 3
12.Printer Caps 4Printer Caps 4
13.Printer Caps 5Printer Caps 5
14.Printer Caps 6Printer Caps 6
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.