如何在C#WinForms中清楚地将面板内容(基本上是标签)打印到打印机上

时间:2013-07-15 09:33:58

标签: c# printing label panel printdocument

我有这个代码用于将面板打印到打印机。它有标签,那些标签是我唯一要打印的东西。它有效但打印时标签打印不清晰。它像模糊的东西。

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

0 个答案:

没有答案