Home All Groups Group Topic Archive Search About
Author
23 Mar 2006 2:51 PM
Bryan Simmonds
Hi,

I have a problem that I recently solved and thought I would throw it out to
see if anyone can explain why I had to use the particular solution.

I have an application that prints a series of numbers to any printer.  It
was developed in C# for .NET 2.0 Framework. The code looked like this

//variable to hold the last Page and Print settings
private PageSettings lastPageSettings;

public FormMain()
{
    InitializeComponent();
    lastPageSettings = new PageSettings();
}

private void runToolStripMenuItem_Click(object sender, EventArgs e)
{

    PrintDocument pd = new PrintDocument();

    FormNumberer thisForm = (FormNumberer)this.ActiveMdiChild;
    pd.PrintPage += new PrintPageEventHandler(thisForm.RunPage);

    pd.DefaultPageSettings = lastPageSettings;

    printDialog.Document = pd;

    if (printDialog.ShowDialog() == DialogResult.OK)
        pd.Print();
}

Here is the issue.  The above code works fine on a Wndows XP Machine.  When
the application is copied to a Windows 2000 Machine and executed I get a
memory error at the line pd.Print().  Now while debugging I observed that
the PrintDialog placed the printer settings into pd.PrinterSettings, but not
into pd.DefaultPageSettings.PrinterSettings.  So therefore the two variables
would contain different printers if the default printer was not used.

So I made this adjustment:

    if (printDialog.ShowDialog() == DialogResult.OK)
    {
        pd.DefaultPageSettings.PrinterSettings =
printDialog.PrinterSettings;
        pd.Print();
    }

And now everything works fine.

Does anyone have a clue as to why this may be?

Thanks,

Bryan

AddThis Social Bookmark Button