2013-05-20 40 views
1

我有這樣的方法應該產生什麼,我需要打印:的PrintDocument上來空白

private void myPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 
    { 

     e.Graphics.PageUnit = GraphicsUnit.Inch; 
     e.Graphics.DrawImage(makeBarcode(), 500, 1000); 
     e.Graphics.DrawString("Do Not Seperate", makeFont(), Brushes.Black, 100, 2); 
     e.Graphics.DrawString("Choking Hazard", makeFont(), Brushes.Black, 200, 2); 
    } 

如何過,當我打印出來,它出現空白,當我看着它在PrintPreviewDialog上談到了毯子。我在這裏錯過了什麼?

這是我的構造函數的方式:

public Form1() 
    { 
     InitializeComponent(); 
     this.myPrintDocument.PrintPage += new 
      System.Drawing.Printing.PrintPageEventHandler 
      (this.myPrintDocument_PrintPage); 
    } 

馬克

private Image makeBarcode() 
    { 
     InventoryBLL ibll = new InventoryBLL(); 
     Barcode b = new Barcode(); 
     b.IncludeLabel = true; 
     b.Height = 35; 
     b.Width = 200; 
     b.BackColor = Color.White; 
     b.ForeColor = Color.Black; 
     b.Alignment = BarcodeLib.AlignmentPositions.CENTER; 
     return b.Encode(TYPE.CODE128, ibll.getFNSKU(txtASIN.Text)); 

    } 
    private Font makeFont() 
    { 
     Font myFont = new Font("arial", 10); 
     return myFont; 
    } 
+0

你需要顯示你的makeFont和你的makebarcode方法。 –

+0

你看過'e.MarginBounds()'並確定你正在頁面內繪製嗎? – ja72

+0

@MarkHall我加了這兩個方法。 –

回答

1
e.Graphics.PageUnit = GraphicsUnit.Inch; 
    ... 
    e.Graphics.DrawString("Choking Hazard", ..., 200, 2); 

該字符串會在200英寸到打印。假設你的紙張不是那麼大,8英寸是典型的。你看不到紙上有什麼。考慮改變PageUnit或使用更小的浮點打印位置。