在c#中打印图片框 [英] print picturebox in c#

查看:85
本文介绍了在c#中打印图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


i在面板中运行时制作超过1000个picturebox现在我想要打印所有这些图片框,这是我的代码,但它打印最后一个图片框,我应该怎么做才能一个一个地打印所有图片框?

Hi i making more than 1000 picturebox in runtime in panel and now i want to print all these picturebox and this is my code but it print the last picturebox, what should i do to it print all picturebox one by one?

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    a = Convert.ToInt32(textBox1.Text);
    for (int i = 0; i < a; i++)
    {
        Bitmap bp = new Bitmap(pic[s].Image, printDoc.DefaultPageSettings.PaperSize.Height, printDoc.DefaultPageSettings.PaperSize.Width);
        Rectangle rec = new Rectangle(label2.Left + 16, label2.Top + 12, label2.Width, label2.Height);
        e.Graphics.DrawImage(pic[s].Image, 0, 0);
        LinearGradientBrush lgb = new LinearGradientBrush(rec, Color.Red, Color.Red, LinearGradientMode.Vertical);
        e.Graphics.DrawString(q.ToString(), label2.Font, lgb, rec);
        bp.Dispose();
        printDoc.DefaultPageSettings.Landscape = true;
    }
}



尊重


With Respect

推荐答案

其实你正在打印所有图片,但在最后只有最后一张图片可见。



首先阅读:绝对新手的.NET打印指南 [ ^ ]



您希望每张图片调用一次PrintPage子程序 - 所以您要做的是当前图片不是最后一张,设置e.HasMorePages = True打印另一张图片页。在该PrintPage子程序中,只打印当前图片并递增当前图片计数器。



Actually you are printing all the pictures on to of each other but at the endf only the last picture is visible.

Start by reading: An absolute beginner's guide to printing in .NET[^]

You want your PrintPage subroutine to be called once per picture - so what you do is if your current picture is not the last one, set e.HasMorePages = True to print another page. In that PrintPage subroutine, only print the current picture and increment the current picture counter.

// Declare this counter at class level...      
int currentPicture = 0;

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            a = Convert.ToInt32(textBox1.Text);

                Bitmap bp = new Bitmap(pic[ currentPicture ].Image, printDoc.DefaultPageSettings.PaperSize.Height, printDoc.DefaultPageSettings.PaperSize.Width);
                Rectangle rec = new Rectangle(label2.Left + 16, label2.Top + 12, label2.Width, label2.Height);
                e.Graphics.DrawImage(pic[ currentPicture ].Image, 0, 0);
                LinearGradientBrush lgb = new LinearGradientBrush(rec, Color.Red, Color.Red, LinearGradientMode.Vertical);
                e.Graphics.DrawString(q.ToString(), label2.Font, lgb, rec);
                bp.Dispose();
                printDoc.DefaultPageSettings.Landscape = true;
            

       if (currentPicture < a)
       { 
           // There are more pictures to print
           currentPicture +=1;
           e.HasMorePages = true;
       }
        }


这篇关于在c#中打印图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆