gpt4 book ai didi

c# - 打印前显示打印对话框

转载 作者:太空狗 更新时间:2023-10-29 19:57:12 25 4
gpt4 key购买 nike

我想在打印文档之前显示打印对话框,以便用户可以在打印之前选择另一台打印机。打印代码为:

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);
}

此代码是否能够打印当前表单?

最佳答案

你必须使用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;用于显示对话窗口。

关于c# - 打印前显示打印对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15985909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com