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.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 » 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
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.