简体   繁体   English

PrintDocument空白

[英]PrintDocument coming up blank

I have this method that should generate what I need to print: 我有这种方法应该生成我需要打印的内容:

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

How ever when I print it, it comes up blanks and when I look at it in PrintPreviewDialog it comes up blanket. 但是当我打印它时,它变成空白,而当我在PrintPreviewDialog中查看它时,它变成空白。 What I am missing here? 我在这里想念的是什么?

This is my constructor by the way: 顺便说一下,这是我的构造函数:

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

For Mark 对于马克

    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;
    }
   e.Graphics.PageUnit = GraphicsUnit.Inch;
   ...
   e.Graphics.DrawString("Choking Hazard", ..., 200, 2);

That string is going to print at 200 inches. 该字符串将在200英寸处打印。 Somewhat safe to assume that your paper isn't that big, 8 inch is about typical. 可以肯定地说,纸张不是那么大,通常是8英寸。 You cannot see what's off the paper. 您看不到纸上的内容。 Consider changing the PageUnit or using much smaller floating point print positions. 考虑更改PageUnit或使用更小的浮点打印位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM