none
VS 2015 C# - Unable to close Print Preview Dialog box after printing RRS feed

  • Question

  • Greetings everyone,

    I'm developing a VS 2015 C# WinForms application with MySQL and ran into a very annoying issue in regards to printing my form.  The form prints perfectly, exactly the way I want, but I've tried everything to make the Print Preview Dialog box close after printing, but to no avail.  Any suggestions?  I really appreciate your time and help!

    Best regards,

    JC

    Here's the code:

            private void printButton_Click(object sender, EventArgs e)
            {
                printButton.Visible = false;
                printDocument1.DefaultPageSettings.Landscape = true;
                CaptureScreen();
                printDialog1.AllowSelection = true;
                printDialog1.AllowSomePages = true;

                if (printDialog1.ShowDialog() == DialogResult.OK)
                {
                    if (printPreviewDialog1.ShowDialog() == DialogResult.OK)
                    {

                          printPreviewDialog1.Close();

                          printButton.Visible = true;
                    }
                }
            }


    jcrcarmo


    • Edited by JC Carmo Saturday, August 17, 2019 4:53 PM mispelling
    Saturday, August 17, 2019 4:40 PM

All replies

  • You can use a Boolean :

    bool bClose = false;
    PrintPreviewDialog printPreviewDialog1;
    private void printDocument1_EndPrint(System.Object sender, System.Drawing.Printing.PrintEventArgs e)
    {  
        if (!bClose)
            bClose = true;
        else
            printPreviewDialog1.Close();
    }
    printDocument1.EndPrint += new PrintEventHandler(printDocument1_EndPrint);

    if (printDialog1.ShowDialog() == DialogResult.OK)
    {
        bClose = false;
        DialogResult dr = printPreviewDialog1.ShowDialog();
    }




    Sunday, August 18, 2019 3:03 PM