Select Printer and pages after PrintPreview

  • Thread starter Thread starter Selçuk Yazar
  • Start date Start date
S

Selçuk Yazar

Hi,

How can we select printer and print page count etc. after usser preview the
document in c# application like winword pressing "Print...." button.

thanks in advance.

--
Bilgi Sistemleri Grubu
TUBITAK
ULUSAL METROLOJI ENSTITUSU
Tel : 0262 679 50 00 / 2215
Fax: 0262 679 50 01
e-mail: (e-mail address removed)
 
I could not understand the question clearly. Would u like to enumarate
printers and get number of copies? It is a standard dialog named as
PrintDialog..

If so, example code is given below
using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

namespace WindowsApplication3

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

private System.Windows.Forms.Button button1;

private System.Windows.Forms.PrintDialog PrintDialog1;

// Declare the PrintDocument object.

private System.Drawing.Printing.PrintDocument docToPrint =

new System.Drawing.Printing.PrintDocument();


// The PrintDialog will print the document

// by handling the document's PrintPage event.

private void document_PrintPage(object sender,

System.Drawing.Printing.PrintPageEventArgs e)

{

// Insert code to render the page here.

// This code will be called when the control is drawn.

// The following code will render a simple

// message on the printed document.

string text = "In document_PrintPage method.";

System.Drawing.Font printFont = new System.Drawing.Font

("Arial", 35, System.Drawing.FontStyle.Regular);

// Draw the content.

e.Graphics.DrawString(text, printFont,

System.Drawing.Brushes.Black, 10, 10);

}

#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.button1 = new System.Windows.Forms.Button();

this.PrintDialog1 = new System.Windows.Forms.PrintDialog();

this.SuspendLayout();

//

// button1

//

this.button1.Location = new System.Drawing.Point(104, 40);

this.button1.Name = "button1";

this.button1.TabIndex = 0;

this.button1.Text = "button1";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 266);

this.Controls.Add(this.button1);

this.Name = "Form1";

this.Text = "Form1";

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}


// This method will set properties on the PrintDialog object and

// then display the dialog.

private void button1_Click(object sender, System.EventArgs e)

{

// Allow the user to choose the page range he or she would

// like to print.

PrintDialog1.AllowSomePages = true;

// Show the help button.

PrintDialog1.ShowHelp = true;

// Set the Document property to the PrintDocument for

// which the PrintPage Event has been handled. To display the

// dialog, either this property or the PrinterSettings property

// must be set

PrintDialog1.Document = docToPrint;

DialogResult result = PrintDialog1.ShowDialog();

// If the result is OK then print the document.

if (result==DialogResult.OK)

{

docToPrint.Print();

}

}

}

}

this sample has taken from MSDN library....
 
Back
Top