Exemple #1
0
    void MenuFilePrintOnClick(object obj, EventArgs ea)
    {
        // Create PrintDocument.

        PrintDocument prndoc = new PrintDocument();

        // Create dialog box and set PrinterName property.

        PrinterSelectionDialog dlg = new PrinterSelectionDialog();

        dlg.PrinterName = prndoc.PrinterSettings.PrinterName;

        // Show dialog box and bail out if not OK.

        if (dlg.ShowDialog() != DialogResult.OK)
        {
            return;
        }

        // Set PrintDocument to selected printer.

        prndoc.PrinterSettings.PrinterName = dlg.PrinterName;

        // Set remainder of PrintDocument properties and commence.

        prndoc.DocumentName = Text;
        prndoc.PrintPage   += new PrintPageEventHandler(OnPrintPage);
        prndoc.Print();
    }
    void MenuFilePrintOnClick(object obj, EventArgs ea)
    {
        // Create PrintDocument.

        PrintDocument prndoc = new PrintDocument();

        // Create dialog box and set PrinterName property.

        PrinterSelectionDialog dlg = new PrinterSelectionDialog();

        dlg.PrinterName = prndoc.PrinterSettings.PrinterName;

        // Show dialog box and bail out if not OK.

        if (dlg.ShowDialog() != DialogResult.OK)
        {
            return;
        }

        // Set PrintDocument to selected printer.

        prndoc.PrinterSettings.PrinterName = dlg.PrinterName;

        // Set printer resolution to "draft".

        foreach (PrinterResolution prnres in
                 prndoc.PrinterSettings.PrinterResolutions)
        {
            if (prnres.Kind == PrinterResolutionKind.Draft)
            {
                prndoc.DefaultPageSettings.PrinterResolution = prnres;
            }
        }

        // Set remainder of PrintDocument properties.

        prndoc.DocumentName       = Text;
        prndoc.PrintPage         += new PrintPageEventHandler(OnPrintPage);
        prndoc.QueryPageSettings += new QueryPageSettingsEventHandler
                                        (OnQueryPageSettings);
        // Commence printing.

        iPageNumber = 1;
        prndoc.Print();
    }