Of course it would do that because you create a brand new instance of the dialog using
PageSetupDialog pageSetup = new PageSetupDialog();
What else could you expect?
You really need to re-use the same object over and over. The best and most universal way to do that on-demand using
lazy initialization pattern, see
http://en.wikipedia.org/wiki/Lazy_initialization[
^].
I would simply keep the reference to the dialog as a field of the main form, so the whole picture would look like this:
public class MainForm : Form {
PageSetupDialog PageSetupDialog {
get {
if (fPageSetupDialog == null) {
fPageSetupDialog = new PageSetupDialog();
fPageSetupDialog.PrinterSettings = new System.Drawing.Printing.PrinterSettings();
fPageSetupDialog.PageSettings = new System.Drawing.Printing.PageSettings();
fPageSetupDialog.EnableMetric = false;
}
return fPageSetupDialog;
}
PageSetupDialog fPageSetupDialog;
void SomeMethodWherePageSetupDialogIsUsed() {
PageSetupDialog.ShowDialog();
}
}
—SA