Print Dialogs : 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.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 » GUI Windows Form » PrintScreenshots 
Print Dialogs

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

Publisher: Apress
ISBN: 159059035X
*/

using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace PrintDialogs_c
{
    public class PrintDialogs : System.Windows.Forms.Form
    {
    private Image MyImage;
    private PrintDocument pd;
    private PrintPreviewDialog Preview;

    private System.Windows.Forms.Button cmdShow;
    private System.Windows.Forms.Label lblPrint;
        private System.ComponentModel.Container components = null;

        public PrintDialogs()
        {
            InitializeComponent();

      MyImage = Bitmap.FromFile(@"d:\colorbars.jpg");
      Preview = new PrintPreviewDialog();
      Preview.UseAntiAlias = true;
        }

        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.cmdShow = new System.Windows.Forms.Button();
      this.lblPrint = new System.Windows.Forms.Label();
      this.SuspendLayout();
      // 
      // cmdShow
      // 
      this.cmdShow.Location = new System.Drawing.Point(352344);
      this.cmdShow.Name = "cmdShow";
      this.cmdShow.Size = new System.Drawing.Size(7224);
      this.cmdShow.TabIndex = 0;
      this.cmdShow.Text = "Show";
      this.cmdShow.Click += new System.EventHandler(this.cmdShow_Click);
      // 
      // lblPrint
      // 
      this.lblPrint.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.lblPrint.Location = new System.Drawing.Point(14432);
      this.lblPrint.Name = "lblPrint";
      this.lblPrint.Size = new System.Drawing.Size(280136);
      this.lblPrint.TabIndex = 1;
      // 
      // PrintDialogs
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(442373);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.lblPrint,
                                                                  this.cmdShow});
      this.MaximizeBox = false;
      this.MinimizeBox = false;
      this.Name = "PrintDialogs";
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
      this.Text = "PrintDialogs";
      this.Load += new System.EventHandler(this.PrintDialogs_Load);
      this.ResumeLayout(false);

    }
        #endregion

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

    private void PrintDialogs_Load(object sender, System.EventArgs e)
    {
      pd = new PrintDocument();
      pd.PrintPage += new PrintPageEventHandler(this.pd_Print);
      
      Preview.Document = pd;
    }

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

    private void pd_Print(object sender, PrintPageEventArgs e)
    {
      lblPrint.Text += "pd_Print pd= " + sender.ToString() "\n" ;
      DrawIt(e.Graphics);
    }

    private void DrawIt(Graphics G)
    {
      G.SmoothingMode=SmoothingMode.AntiAlias;
      G.DrawImage(MyImage, 1010);

      LinearGradientBrush B = new LinearGradientBrush(
                              new Rectangle(005010),
                              Color.Red, Color.Blue, 
                              LinearGradientMode.ForwardDiagonal);
      G.FillEllipse(B, 1020020075);

      G.DrawString("Print Preview Test"
                   new Font("Comic Sans MS",24), B, 50275);
    }

    private void cmdShow_Click(object sender, System.EventArgs e)
    {
      Preview.WindowState = FormWindowState.Maximized;
      pd.DocumentName = DateTime.Now.Ticks.ToString();
      Preview.ShowDialog();
    }
    }
}


           
       
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 EventsPrint Events
6.UI PrintUI Print
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
w__w__w__.___ja___v___a2_s__._c___o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.