在C#中打印Windows窗体内容 [英] Print Windows Form content in C#

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

问题描述

我有一个Windows表单,其中包含图片&该图像上的一些文本框.在将这些文本框和该图像一起填充后,我需要打印内容.我使用了下面的代码,但是它只打印图像,而不打印文本框中的值.

I have a windows form which contains an image & some textboxes on that image. I need to print contents after I fill those textboxes along with that image. I''ve used below code, but it only prints the image, not the values in textboxes.

private void pictureBox1_DoubleClick(object sender, EventArgs e)
       {
           PrintDocument pd = new PrintDocument();
           pd.PrintPage += new PrintPageEventHandler(PrintImage);
           pd.Print();

       }


private void PrintImage(object o, PrintPageEventArgs e)
        {
            int x = SystemInformation.WorkingArea.X;
            int y = SystemInformation.WorkingArea.Y;
            int width = this.Width;
            int height = this.Height;

            Rectangle bounds = new Rectangle(x, y, width, height);

            Bitmap img = new Bitmap(width, height);

            this.DrawToBitmap(img, bounds);
            Point p = new Point(100, 100);
            e.Graphics.DrawImage(img, p);
        }

推荐答案

然后,您需要扩展PrintImage方法,使其包含以下内容:
Then you need to expand the PrintImage method to include something along the line of:
this.DrawToBitmap(img, bounds);
Point p = new Point(100, 100);
e.Graphics.DrawImage(img, p);
// Now add a string...
e.Graphics.DrawString("Hello World!", new Font("Arial", 16), Brushes.Black, new PointF(100.0F, 100.0F));


http://msdn.microsoft.com/zh-CN/library/6he9hz8c.aspx [ http://www.c-sharpcorner.com/UploadFile /srajlaxmi/printing-windows-form-in-C-Sharp-net/ [
http://msdn.microsoft.com/en-us/library/6he9hz8c.aspx[^]
http://www.c-sharpcorner.com/UploadFile/srajlaxmi/printing-windows-form-in-C-Sharp-net/[^]


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

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