2013-04-01 104 views
3

我有下面的圖片框我填充條形碼,然後嘗試打印。C#PrintDocument打印空白頁面。爲什麼?

下面的代碼:

private void button1_Click(object sender, EventArgs e) 
{ 

    printDocument1.OriginAtMargins = true; 
    printDocument1.DocumentName = "TEST IMAGE PRINTING"; 

    printDialog1.Document = printDocument1; 
    printDialog1.ShowDialog(); 
    printDocument1.Print(); 

} 


private void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e) 
{ 
    System.Drawing.Graphics formGraphics = System.Drawing.Graphics.FromImage(picpdf417.Image); 
} 

回答

4

您需要實際繪製圖像:

private void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e) 
{ 
    e.Graphics.DrawImage(picpdf417.Image, Point.Empty); 
} 
+0

你真棒感謝。只是一個後續快速問題。在給定某些x和y位置的情況下,如何在同一頁上打印2個圖片框? – ASPiRE

+0

@Vini我的示例使用Point.Empty,它是(0,0)。您必須測量第一張圖像並調整第二張圖像的DrawImage的位置。 PrintPageEventArgs的「e」變量將保存一些空間信息,例如「e.MarginBounds」和「e.PageBounds」等。 – LarsTech

+0

K.我找到了在打印文檔上定位2個圖片框的方法。我需要做的就是根據我的座標重新調整它們的大小。有什麼想法嗎? – ASPiRE