我正在使用WinForms。在我的表格中,我有一個圖片框和一個可以在圖片框中打印圖片的按鈕。在打印預覽中繪製邊框但邊框不應打印C#
在我的代碼中,當您單擊打印按鈕時,程序會在圖像周圍顯示一個矩形框的打印預覽。我畫了這個矩形框,因爲我有特定類型的紙張,我打印到。這些報紙在邊界上有圖片。用戶無法打印紙張上的圖片。我只想通知用戶,如果您在打印預覽中傳遞這些矩形邊界線,您將在紙張上的圖片上打印。
目標:當我點擊打印按鈕時,我想看到帶矩形邊框的打印預覽紙,但我不想打印矩形邊框。我只是想要打印圖像。
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
我要試試@LarsTech – taji01
@ taji01點擊打印按鈕時,一定要將它重置爲false。 –