How to show "page setup" and "printer setup" as modeless forms?

YD4 picture YD4 · Nov 12, 2012 · Viewed 7.5k times · Source

Is possible to show "page setup" and "printer setup" as modeless forms? I used code as follows, but that forms display as modal forms:

    // page setup
    private void btnPageSetup_Click(object sender, EventArgs e)
    {
        this.pageSetupDialog1.PageSettings = new PageSettings();
        this.pageSetupDialog1.PrinterSettings = this.printDocument1.PrinterSettings;
        this.pageSetupDialog1.ShowDialog();
        if (this.pageSetupDialog1.PageSettings != null)
        {
            this.printDocument1.DefaultPageSettings = this.pageSetupDialog1.PageSettings;
        }
    }

    // print setup
    private void btnPrintSetup_Click(object sender, EventArgs e)
    {
        this.pageSetupDialog1.Document = this.printDocument1;
        if (this.pageSetupDialog1.ShowDialog() == DialogResult.OK)
        {
            this.printDocument1.Print();
        }
    }

Answer

Rawling picture Rawling · Nov 12, 2012

You can show a form as non-modal by calling Show rather than ShowDialog.

However, you'll also have to shuffle your code around, because your main form will no longer sit and wait for one of the subforms to close in order to check what the user did.

For example, you'll have to change the Print Setup code such that your PageSetupDialog prints the document itself when the user clicks OK, rather than relying on the main form to act when the user has clicked OK.

Similarly, you'll need to change the Page Setup code such that your PageSetupDialog sets Document.DefaultPageSettings itself, rather than "returning" settings in the PageSettings property and relying on the main form handling them.