【问题标题】:PrintDocument coming up blankPrintDocument 出现空白
【发布时间】:2013-05-20 19:27:00
【问题描述】:

我有这个方法可以生成我需要打印的内容:

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

【问题讨论】:

  • 你需要展示你的makeFont和你的makebarcode方法。
  • 您是否查看了e.MarginBounds() 并确保您在页面内绘图?
  • @MarkHall 我添加了这两种方法。
  • 你试过打电话给e.Graphics.Flush()吗?

标签: c# winforms printing printdocument


【解决方案1】:
   e.Graphics.PageUnit = GraphicsUnit.Inch;
   ...
   e.Graphics.DrawString("Choking Hazard", ..., 200, 2);

该字符串将以 200 英寸打印。可以肯定的是,假设您的纸张不是那么大,8 英寸是典型的。你看不到纸上的东西。考虑更改 PageUnit 或使用更小的浮点打印位置。

【讨论】:

    猜你喜欢
    • 2015-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    • 2016-12-10
    • 1970-01-01
    • 2015-03-07
    相关资源
    最近更新 更多