【发布时间】:2015-11-06 22:41:38
【问题描述】:
我正在使用 WinForms。在我的表单中,我有一个图片框和一个打印图片框中图片的按钮。
在我的代码中,当您单击打印按钮时,程序会在图像周围显示一个带有矩形框的打印预览。我画了这个矩形框,因为我有要打印的特定类型的纸张。这些文件的边框上有图片。用户不能在纸上打印图片。我只是想告诉用户,如果您在打印预览中传递这些矩形边界线,您将在纸上的图片之上打印。
目标:当我单击打印按钮时,我希望看到带有矩形边框的打印预览纸,但我不想打印矩形边框。我只想打印图像。
private void button1_Click(object sender, EventArgs e)
{
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
var bmp = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
this.pictureBox1.DrawToBitmap(bmp, this.pictureBox1.ClientRectangle);
e.Graphics.DrawRectangle(Pens.Salmon, 25, 25, 500, 1000);
e.Graphics.DrawImage(bmp, 25, 25, 500, 500); //Gets the input from the textboxes
}
【问题讨论】:
-
创建一个名为“drawBorder”的布尔变量,当您单击预览按钮时该变量为真。
-
我要试试@LarsTech
-
@taji01 请务必在单击打印按钮时将其重置为 false。
-
我有点迷路了,但是像这样,bool drawBorder = false;并在 preview_button_click{ drawBorder = true} @RonBeyer
标签: c# .net image winforms printing