0

我正在尝试使用下面的代码打印位图,但它不起作用。我不知道为什么......

   private void btnImprimir_Click(object sender, EventArgs e)
    {
        PrintDocument pd = new PrintDocument();
        pd.PrintPage += PrintPage;
        pd.Print(); 
    }

    private void PrintPage(object o, PrintPageEventArgs e)
    {
        button1.Visible = false;
        button2.Visible = false;
        button3.Visible = false;
        button4.Visible = false;
        Bitmap bitmap = new Bitmap(this.Width, this.Height);
        this.DrawToBitmap(bitmap, this.ClientRectangle);
        Point loc = new Point(this.Width, this.Height);
        e.Graphics.DrawImage(bitmap, loc);
        button1.Visible = true;
        button2.Visible = true;
        button3.Visible = true;
        button4.Visible = true;
    }
4

2 回答 2

3

用这种方式

Image bmIm;
private void PrintImage(Image img)
{
  bmIm = img;
  PrintDocument pd = new PrintDocument();
  pd.OriginAtMargins = true;
  pd.DefaultPageSettings.Landscape = true;
  pd.PrintPage += pd_PrintPage;
  pd.Print();
}
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
  double cmToUnits = 100 / 2.54;
  e.Graphics.DrawImage(bmIm, 0, 0,(float)(27 * cmToUnits),(float)(18 * cmToUnits));
}
于 2013-01-14T14:00:37.063 回答
1

看起来您的事件没有正确连接(除非我们缺少一些代码):

pd.PrintPage += this.PrintPage;

您试图分配pd_PrintPage代码示例中没有的内容,所以我不知道它应该做什么。

于 2013-01-14T14:39:11.193 回答