无法打印页面,document_PrintPage不存在 [英] unable to print page ,document_PrintPage doesnt exist

查看:119
本文介绍了无法打印页面,document_PrintPage不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用System;

使用System.Collections.Generic;

使用System.ComponentModel;

使用System.Data;

使用System.Drawing;

使用System.Linq;

使用System.Text;

使用System.Threading.Tasks ;

使用System.Windows.Forms;

使用System.Drawing.Printing;

使用System.Drawing.Imaging;



命名空间WindowsFormsApplication1

{

公共部分课程门票:表格

{

private System.Drawing.Printing.PrintDocument docToPrint;

public Admission()

{

InitializeComponent();

docToPrint = new System.Drawing.Printing.PrintDocument();

docToPrint.PrintPage + = document_PrintPage; // ERROR HERE

}



private void exitToolStripMenuItem_Click(object sender,EventArgs e)

{

this.Close();

}





private void printToolStripMenuItem_Click(object发件人,EventArgs e)

{

PrintDialog PrintDialog1 = new PrintDialog();

//允许用户选择他或他的页面范围她会

//喜欢打印。

PrintDialog1.AllowSomePages = true;



//显示帮助按钮。

PrintDialog1.ShowHelp = true;



//将Document属性设置为PrintDocument

//已经处理了PrintPage事件。要显示

//对话框,必须设置此属性或PrinterSettings属性

//

PrintDialog1.Document = docToPrint; < br $>


DialogResult result = PrintDialog1.ShowDialog();



//如果结果是OK则打印文件。

if(result == DialogResult.OK)

{

docToPrint.Print();

}

}





}

}

解决方案

您需要为打印文档添加事件处理程序,例如



  private   void  document_PrintPage( object  sender,PrintPageEventArgs ev)
{
// 打印文档代码......
}



检查PrintDocument.PrintPage事件文档 [ ^


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Drawing.Imaging;

namespace WindowsFormsApplication1
{
public partial class Admission : Form
{
private System.Drawing.Printing.PrintDocument docToPrint;
public Admission()
{
InitializeComponent();
docToPrint = new System.Drawing.Printing.PrintDocument();
docToPrint.PrintPage += document_PrintPage; // ERROR HERE
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}


private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
PrintDialog PrintDialog1 = new PrintDialog();
// 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();
}
}


}
}

解决方案

you need to add event handler for print document, for example

private void document_PrintPage(object sender, PrintPageEventArgs ev)
   {
      // printing document code...
   }


check sample code given in PrintDocument.PrintPage Event documentation [^]


这篇关于无法打印页面,document_PrintPage不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆