-1

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();
        }
    }
YD4
  • 99
  • 1
  • 4
  • 12

1 Answers1

-1

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.

Rawling
  • 49,248
  • 7
  • 89
  • 127
  • Btw pageSetupDialog1 not support for Show() method, only support ShowDialog(). The reason why I want to make the forms modelless because there is another button, say the "refresh button", which serves to close all the open forms on main form. The problem arises if the modal form actived, a refresh button does not work. – YD4 Nov 12 '12 at 13:15