本文介绍了显示打印对话框打印前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要打印文档前显示打印对话框,使用户可以在打印前选择另一台打印机。在code打印是:
I want to show the print dialog box before printing the document, so the user can choose another printer before printing. The code for printing is:
private void button1_Click(object sender, EventArgs e)
{
try
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(PrintImage);
pd.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ToString());
}
}
void PrintImage(object o, PrintPageEventArgs e)
{
int x = SystemInformation.WorkingArea.X;
int y = SystemInformation.WorkingArea.Y;
int width = this.Width;
int height = this.Height;
Rectangle bounds = new Rectangle(x, y, width, height);
Bitmap img = new Bitmap(width, height);
this.DrawToBitmap(img, bounds);
Point p = new Point(100, 100);
e.Graphics.DrawImage(img, p);
}
将在code能打印当前的形式?
will this code be able to print the current form?
推荐答案
您必须使用 PrintDialog类
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(PrintPage);
PrintDialog pdi = new PrintDialog();
pdi.Document = pd;
if (pdi.ShowDialog() == DialogResult.OK)
{
pd.Print();
}
else
{
MessageBox.Show("Print Cancelled");
}
编辑(从评论)
在 64位
Windows和.NET与某些版本的,你可能必须设置 pdi.UseExDialog = TRUE
;该对话框窗口出现。
On 64-bit
Windows and with some versions of .NET you may have to set pdi.UseExDialog = true
; for the dialog window to appear.
这篇关于显示打印对话框打印前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!