Closing Preview after print

Stimulsoft Reports.NET discussion
Post Reply
TGoertler
Posts: 24
Joined: Wed Aug 25, 2010 9:16 am
Location: Gundelsheim/Germany

Closing Preview after print

Post by TGoertler »

Hello,

is there a way to close the report preview window after printing, exporting or email sending?

I use report.show() to open the preview window. I've seen there're events that get fired when printing, exporting, emailing, but I have not found a way to close the form then.

I hope you can help me with this.

Best Regards,
Thomas Görtler
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Closing Preview after print

Post by Alex K. »

Hello,

You can subscribe to the StiReport.CompiledReport.Printed event and add your code to close preview window.
Please see the following code.

Code: Select all

        private StiViewerForm stiVewForm = new StiViewerForm();
        private void bShow_Click(object sender, EventArgs e)
        {
            StiReport report = new StiReport();
            report.Load("e:\\Report.mrt");
            report.Compile();
            report.CompiledReport.Printed += new EventHandler(report_Printing);
            report.Render();
            stiVewForm.Report = report;
            stiVewForm.Show();
        }

        private void report_Printing(object sender, EventArgs e)
        {
            StiReport report = sender as StiReport;
            if ((report.PrinterSettings.PrintDialogResult == DialogResult.OK))
            {
                MessageBox.Show("Printing");
            }
            stiVewForm.Close();            
        }
Thank you.
TGoertler
Posts: 24
Joined: Wed Aug 25, 2010 9:16 am
Location: Gundelsheim/Germany

Closing Preview after print

Post by TGoertler »

Hi Aleksey,

thank you for your reply. I forgot to mention that I use vb.net 2008.

I tried to convert the code to vb.net but I couldn't find StiViewerForm()

Code: Select all

Dim stiVewForm As New StiViewerForm()
gave me an error "StiViewerForm() is undefined".

As far as I understand your code, you create a new StiViewerForm and in the report.Compiled.Printed Event you close it as soon as the printing is successful.
I tried the predefined events of the StiReport Control in VB.NET (there's printing, printed, exported, exporting etc.) but the report never fires these events.

So how could this be reproduced with VB.NET ?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Closing Preview after print

Post by Alex K. »

Hello,

You can use the following code:

Code: Select all

Private stiVewForm As New Stimulsoft.Report.Viewer.StiViewerForm

Private Sub ButtonShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonShow.Click
    Dim report As StiReport = New StiReport()
    report.Load("e:\\Report.mrt")
    report.Compile()
    AddHandler report.CompiledReport.Printed, AddressOf report_Printing
    report.Render()
    stiVewForm.Report = report
    stiVewForm.Show()
End Sub

Private Sub report_Printing(ByVal sender As Object, ByVal e As EventArgs)
    Dim report As StiReport = TryCast(sender, StiReport)
    If (report.PrinterSettings.PrintDialogResult = DialogResult.OK) Then
        MessageBox.Show("Printing")
    End If
    stiVewForm.Close()
End Sub
Thank you.
Post Reply