Page 1 of 1

Closing Preview after print

Posted: Thu Sep 23, 2010 9:59 am
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

Closing Preview after print

Posted: Fri Sep 24, 2010 2:21 am
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.

Closing Preview after print

Posted: Fri Sep 24, 2010 5:51 am
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 ?

Closing Preview after print

Posted: Fri Sep 24, 2010 8:18 am
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.