首頁>Club>
10
回覆列表
  • 1 # lanfengz3

    步驟如下:

    建立一個PrintDialog的例項。如下:

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

    建立一個PrintDocument的例項.如下:

    System.Drawing.Printing.PrintDocument docToPrint =

    new System.Drawing.Printing.PrintDocument();

    設定印表機開始列印的事件處理函式.函式原形如下:

    void docToPrint_PrintPage(object sender,

    System.Drawing.Printing.PrintPageEventArgs e)

    將事件處理函式新增到PrintDocument的PrintPage事件中。

    docToPrint.PrintPage+=new PrintPageEventHandler(docToPrint_PrintPage);

    設定PrintDocument的相關屬性,如:

    PrintDialog1.AllowSomePages = true;PrintDialog1.ShowHelp = true;

    把PrintDialog的Document屬性設為上面配置好的PrintDocument的例項:

    PrintDialog1.Document = docToPrint;

    呼叫PrintDialog的ShowDialog函式顯示列印對話方塊:

    DialogResult result = PrintDialog1.ShowDialog();

    根據使用者的選擇,開始列印:

    if (result==DialogResult.OK)

    {

    docToPrint.Print();

    }

    using System;

    using System.Drawing.Printing;

    using System.Windows.Forms;

    using System.IO;

    namespace EDImageSystem

    {

    ///

    /// PrintService 的摘要說明。

    ///

    public class PrintService

    {

    public PrintService()

    {

    //

    // TODO: 在此處新增建構函式邏輯

    //

    this.docToPrint.PrintPage+=new PrintPageEventHandler(docToPrint_PrintPage);

    }//將事件處理函式新增到PrintDocument的PrintPage中

    // Declare the PrintDocument object.

    private System.Drawing.Printing.PrintDocument docToPrint =

    new System.Drawing.Printing.PrintDocument();//建立一個PrintDocument的例項

    private System.IO.Stream streamToPrint;

    string streamType;

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

    // then display the dialog.

    public void StartPrint(Stream streamToPrint,string streamType)

    {

    this.streamToPrint=streamToPrint;

    this.streamType=streamType;

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

    // like to print.

    System.Windows.Forms.PrintDialog PrintDialog1=new PrintDialog ();//建立一個PrintDialog的例項。

    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;//把PrintDialog的Document屬性設為上面配置好的PrintDocument的例項

  • 中秋節和大豐收的關聯?
  • 電腦宕機,用優盤啟動不了。怎麼辦?