Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

Here I want to print a winform for that I have addded the following line of coding but it's not working properly. I am looking forward to your valuable suggestions

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

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

Thanks & Regards,
Soumya

[edit]Code block fixed[/edit]
Posted
Updated 15-Apr-13 0:45am
v2
Comments
[no name] 15-Apr-13 6:41am    
Can you specify what is the pd here in your code?
soumyaraj 15-Apr-13 6:56am    
PrintDocument pd = new PrintDocument();
rmksiva 15-Apr-13 6:48am    
Please Mention, Windows App or Web App
soumyaraj 15-Apr-13 6:56am    
windows

1 solution

 
Share this answer
 
Comments
soumyaraj 15-Apr-13 7:20am    
Thank you hip

But When I used the line of coding which u mentioned in the above link After Executing it's showing small print dialog with a cancel button and is written 'Page 1 of Document' Besides one save dialogbox with save type as XPS Document
Nothing is happening After that
vinayakJJ 15-Apr-13 7:26am    
its working perfectly wid me
is it showing blank page to you
make sure that you have generated printpage event of printdocument not copied the event
soumyaraj 15-Apr-13 8:30am    
How can I generate print page event printdocument with out copy,paste?
vinayakJJ 15-Apr-13 8:35am    
take the component printDocument from toolbox from printing tab and drag and drop to your form and then double click on it
soumyaraj 16-Apr-13 2:43am    
But still it's showing the same which I mentioned in the above comment after drag and drop the printdocument from the toolbox and making a click event
Since I Have not connected to printer How can I check whether it's working or not?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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