0

Is it possible, when i open a form with reportviewer inside to print it automatically without need to press the printer button and without show me printdialog.

Just to put a code in Form_Load and to Print it Automatically.

I found this:

 Image printimg;
 private void Form1_Load(object sender, EventArgs e)

 {

 printimg = Image.FromStream(new FileStream("path", FileMode.Open));

 PrintDocument print = new PrintDocument();

 PrinterSettings setting = new PrinterSettings();

 //do something

 print.PrinterSettings = setting;

 print.PrintPage += Print_PrintPage;

 print.Print();

 }

 private void Print_PrintPage(object sender, PrintPageEventArgs e)

 {

 e.Graphics.DrawImage(printimg, new Point());

 }

But which is my path?

DmO
  • 357
  • 2
  • 14
  • `Is it possible, when i open a form with reportviewer` If the ReportViewer had a Print() method then yes. Since it doesn't then no.You could take a bitmap of the form but you won't be happy with the results. – Conrad Frix Mar 08 '16 at 20:03
  • And how will i do this? – DmO Mar 08 '16 at 20:19
  • 1
    I have tried this before, ReportViewer only has a PrintDialog() method, what i ended up doing is setting up a big button that opens the PrintDialog with the predefined print settings. – ArturoAP Mar 08 '16 at 20:38
  • How do you create a bitmap from the screen? Assuming Winforms there's a [CopyFromSreen](https://msdn.microsoft.com/en-us/library/cdcw1c3b.aspx?f=255&MSPPError=-2147217396) seen in [this question](http://stackoverflow.com/q/362986/119477). From WPF it's a little different. – Conrad Frix Mar 09 '16 at 15:32

0 Answers0