Using PrintPreviewDialog : Print Dialog « 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 » Print DialogScreenshots 
Using PrintPreviewDialog
 

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

using System.Drawing.Printing;

public class frmMain : System.Windows.Forms.Form {
    private System.Drawing.Printing.PrintDocument printDoc;
    private System.Windows.Forms.PrintPreviewDialog ppDialog;
    private System.Windows.Forms.Button btnPrint;
    public frmMain() {
        this.printDoc = new System.Drawing.Printing.PrintDocument();
        this.ppDialog = new System.Windows.Forms.PrintPreviewDialog();
        this.btnPrint = new System.Windows.Forms.Button();
        this.SuspendLayout();

        this.printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDoc_PrintPage);

        this.ppDialog.AutoScrollMargin = new System.Drawing.Size(00);
        this.ppDialog.AutoScrollMinSize = new System.Drawing.Size(00);
        this.ppDialog.ClientSize = new System.Drawing.Size(400300);
        this.ppDialog.Enabled = true;
        this.ppDialog.Location = new System.Drawing.Point(19522);
        this.ppDialog.MaximumSize = new System.Drawing.Size(00);
        this.ppDialog.Opacity = 1;
        this.ppDialog.TransparencyKey = System.Drawing.Color.Empty;
        this.ppDialog.Visible = false;

        this.btnPrint.Location = new System.Drawing.Point(5228);
        this.btnPrint.Text = "Print";
        this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);

        this.AutoScaleBaseSize = new System.Drawing.Size(513);
        this.ClientSize = new System.Drawing.Size(17686);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.btnPrint});
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.ResumeLayout(false);

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

    private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) {
        PrinterSettings pSettings = new PrinterSettings();
        Font printFont = new Font("Arial"12);

        int nTextPosY = e.MarginBounds.Top;
        int nTextPosX = e.MarginBounds.Left;
        int nHeight = (int)printFont.GetHeight(e.Graphics);

        foreach (string sPtr in PrinterSettings.InstalledPrinters) {
            pSettings.PrinterName = sPtr;
            if (pSettings.IsValid) {
                e.Graphics.DrawString(sPtr, printFont, Brushes.Black, nTextPosX, nTextPosY + 5);
                e.Graphics.DrawString("Can Duplex: " + pSettings.CanDuplex.ToString(),
                    printFont, Brushes.Black, nTextPosX + 10, nTextPosY + (+ nHeight));
                e.Graphics.DrawString("Is Default: " + pSettings.IsDefaultPrinter.ToString(),
                    printFont, Brushes.Black, nTextPosX + 10, nTextPosY + (+ nHeight * 2));
                e.Graphics.DrawString("Is Plotter: " + pSettings.IsPlotter.ToString(),
                    printFont, Brushes.Black, nTextPosX + 10, nTextPosY + (+ nHeight * 3));
                e.Graphics.DrawString("Landscape Angle: " + pSettings.LandscapeAngle.ToString(),
                    printFont, Brushes.Black, nTextPosX + 10, nTextPosY + (+ nHeight * 4));
                e.Graphics.DrawString("Maximum Copies: " + pSettings.MaximumCopies.ToString(),
                    printFont, Brushes.Black, nTextPosX + 10, nTextPosY + (+ nHeight * 5));
                e.Graphics.DrawString("Maximum Page: " + pSettings.MaximumPage.ToString(),
                    printFont, Brushes.Black, nTextPosX + 10, nTextPosY + (+ nHeight * 6));
                e.Graphics.DrawString("Minimum Page: " + pSettings.MinimumPage.ToString(),
                    printFont, Brushes.Black, nTextPosX + 10, nTextPosY + (+ nHeight * 7));
                e.Graphics.DrawString("Supports Color: " + pSettings.SupportsColor.ToString(),
                    printFont, Brushes.Black, nTextPosX + 10, nTextPosY + (+ nHeight * 8));
                nTextPosY = nTextPosY + ((+ nHeight * 8+ nHeight);
            }
        }
    }
    private void btnPrint_Click(object sender, System.EventArgs e) {
        ppDialog.Document = printDoc;
        ppDialog.ShowDialog();
    }
}

 
Related examples in the same category
1.Steps through the common dialogs. Does nothing else usefulSteps through the common dialogs. Does nothing else useful
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.