0

我有此代码用于将面板打印到打印机。它有标签,而这些标签是我唯一想要打印的东西。它可以工作,但打印时,标签打印不清晰。它就像模糊或什么的。

private void btnPrint_Click(object sender, EventArgs e)
{ 
     Print(panel1);
}

public void Print(Panel pnl)
{
        pannel = pnl;
        GetPrintArea(pnl);

        if (cmbPrinter.SelectedIndex != -1)
        {
            printdoc1.PrinterSettings.PrinterName = cmbPrinter.SelectedItem.ToString();
        }

        if (batchForm.printInBatch)
            printdoc1.Print();
        else
        {
            previewdlg.Document = printdoc1;
            previewdlg.ShowDialog();
        }
}

public void GetPrintArea(Panel pnl)
{
        MemoryImage = new Bitmap(pnl.Width, pnl.Height);
        Rectangle rect = new Rectangle(0, 0, pnl.Width, pnl.Height);
        pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pnl.Width, pnl.Height));
}

protected override void OnPaint(PaintEventArgs e)
{
        if (MemoryImage != null)
        {
            e.Graphics.DrawImage(MemoryImage, 0, 0);
            base.OnPaint(e);
        }
}

public void printdoc1_PrintPage(object sender, PrintPageEventArgs e)
{
        Rectangle pagearea = e.PageBounds;
        e.Graphics.DrawImage(MemoryImage, 0, 0);
}
4

0 回答 0