2

我在“C://”中有位图,名称为“1.bmp”、“2.bmp”、“3.bmp”等,我正在尝试打印这些图像但打印文档是空的(图像是在正确的路径)

这是我的代码:

private void button3_Click_1(object sender, EventArgs e)
{
    PrintDocument pd = new PrintDocument();
    for (int indice = 0; indice < nPaginasPDF + 1; indice++)
    {
        pd.PrintPage += new PrintPageEventHandler(Print_Page);
    }
    PrintPreviewDialog dlg = new PrintPreviewDialog();

    dlg.Document = pd;
    dlg.ShowDialog();
    pd.Print();
}       

private void Print_Page(object o, PrintPageEventArgs e)
{
    nPaginasImpressas++;
    System.Drawing.Image i = System.Drawing.Image.FromFile("C:\\" + nPaginasImpressas + ".bmp");
    Point p = new Point(891, 1350);
    e.Graphics.DrawImage(i, p);
}
4

1 回答 1

2

好的,因此打印页面的过程利用了PrintPageEventArgs类而不是多次附加事件。考虑以下代码:

private void button3_Click_1(object sender, EventArgs e)
{
    PrintDocument pd = new PrintDocument();
    pd.PrintPage += new PrintPageEventHandler(Print_Page);
    PrintPreviewDialog dlg = new PrintPreviewDialog();

    dlg.Document = pd;
    dlg.ShowDialog();
    pd.Print();
}       

private void Print_Page(object o, PrintPageEventArgs e)
{
    nPaginasImpressas++;
    System.Drawing.Image i = System.Drawing.Image.FromFile("C:\\" + nPaginasImpressas + ".bmp");
    Point p = new Point(0, 0);
    e.Graphics.DrawImage(i, p);

    e.HasMorePages = File.Exists("C:\\" + (nPaginasImpressas + 1) + ".bmp");
}

此代码应允许您打印多页。但请注意对 - 的更改,Point这对我来说是非常可疑的,然后是HasMorePages.

于 2013-04-30T14:24:46.747 回答