Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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);
        }
Posted

Then you need to expand the PrintImage method to include something along the line of:
C#
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));
 
Share this answer
 
Comments
[no name] 13-Nov-12 3:31am    
But this is like a submission form for a user. So user has to inset values to the textboxes & those details should be printed
OriginalGriff 13-Nov-12 3:35am    
So retrieve the values from your text boxes, and use them where I put "Hello World!"...

Is this really that difficult for you?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900