How to detect if the-user pressing PRINT button at PRINT DIALOG?

Stimulsoft Reports.NET discussion
Post Reply
stvhui
Posts: 51
Joined: Wed Apr 22, 2009 3:12 am

How to detect if the-user pressing PRINT button at PRINT DIALOG?

Post by stvhui »

Hello to you,
I'm newbie using VB.NET 2005, Stimulsoft Report 2010 for .NET Winform

As we know, when report showing on viewer, Viewer have a print button, when clicked then the PRINT DIALOG show, If user pressing PRINT button, then report printing on printer.

How to detect it, when PRINT button pressed then msgbox("PRINTING")

Please guide me and show me by code in VB.NET

Thanks in advance

Regards,
Steven
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

How to detect if the-user pressing PRINT button at PRINT DIALOG?

Post by Ivan »

Hello,

Please check the following article in our knowledgebase:
http://stimulsoft.helpserve.com/index.p ... icleid=104
You should use the static PrintingDocument event of the StiPreviewControl class.
See a code below for processing printing of a rendered report:

Code: Select all

AddHandler StiPreviewControl.PrintingDocument, New EventHandler(AddressOf Form1.OnPrintingDocument)

Code: Select all

Private Shared Sub OnPrintingDocument(ByVal sender As Object, ByVal e As EventArgs)
  ' Show your messagebox here
  Dim Report As StiReport = TryCast(sender, StiReport)
  Report.Print()
End Sub
Thank you.
stvhui
Posts: 51
Joined: Wed Apr 22, 2009 3:12 am

How to detect if the-user pressing PRINT button at PRINT DIALOG?

Post by stvhui »

Hi Ivan,

Thanks for yr reply.

Yr solution is just detected pressing PRINT button at ReportViewer Control, that is not my point.

My point is : After pressing PRINT button at ReportViewer Control, then The PRINT DIALOG Window showing, this window contains 2 buttons [OK] and [CANCEL].

I just want to detected if pressing/clicking [OK] button.

I'm existing user of DataDynamics, Now GrapeCity Active Report. They have knowledge base/documentation about this.

Please advice and show by code

Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

How to detect if the-user pressing PRINT button at PRINT DIALOG?

Post by Ivan »

Hello,

Please check the following article in our knowledgebase:
http://stimulsoft.helpserve.com/index.p ... ticleid=27
How to know which buttons press user in print dialog box?

You can check property - report.PrinterSettings.PrintDialogResult. See sample below.

Code: Select all

if (report.CompiledReport != null)
  return report.CompiledReport.PrinterSettings.PrintDialogResult
else
  return report.PrinterSettings.PrintDialogResult;
Thank you.
stvhui
Posts: 51
Joined: Wed Apr 22, 2009 3:12 am

How to detect if the-user pressing PRINT button at PRINT DIALOG?

Post by stvhui »

Hello Ivan,

Great!, that's what I want.

I want to code, when After pressing [OK] button at PRINT DIALOG window, then immediately to showing msgbox("PRINTING to PRINTER")

What event should I coded in?

Please advice & show me how?

Thanks
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

How to detect if the-user pressing PRINT button at PRINT DIALOG?

Post by Alex K. »

Hello,

You can use the following code:

Code: Select all

        private void button1_Click(object sender, EventArgs e)
        {
            StiReport report = new StiReport();
            report.Load("D:\\Sample Report.mrt");
            report.Compile();
            report.CompiledReport.Printed += new EventHandler(report_Print);
            report.Show();
        }

        private void report_Print(object sender, EventArgs e)
        {
            StiReport report = sender as StiReport;
            if ((report.PrinterSettings.PrintDialogResult == DialogResult.OK))
            {
                MessageBox.Show("PRINTING to PRINTER");
            }
        }
Thank you.
stvhui
Posts: 51
Joined: Wed Apr 22, 2009 3:12 am

How to detect if the-user pressing PRINT button at PRINT DIALOG?

Post by stvhui »

Hi Aleksey,

Thanks for yr answer, You fullfil what I want.

One more questions, from yr code :
report.compile()

Should always have this line? (because, If not put report.compile seems report also work)
When report.compile needed?

Thanks in advance
Steven
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

How to detect if the-user pressing PRINT button at PRINT DIALOG?

Post by Alex K. »

Hello,

In this case the report.compile() method is used to assign the report.CompiledReport.Printed += new EventHandler(report_Print); event.

Thank you.
Post Reply