Sdílet prostřednictvím


PrintDocument.QueryPageSettings Událost

Definice

Nastane bezprostředně před každou PrintPage událostí.

public:
 event System::Drawing::Printing::QueryPageSettingsEventHandler ^ QueryPageSettings;
public event System.Drawing.Printing.QueryPageSettingsEventHandler QueryPageSettings;
member this.QueryPageSettings : System.Drawing.Printing.QueryPageSettingsEventHandler 
Public Custom Event QueryPageSettings As QueryPageSettingsEventHandler 

Event Type

Příklady

Následující příklad kódu vytiskne dokument s první stránkou barevně, pokud ji tiskárna podporuje. Příklad vyžaduje vytvoření PrintDocument proměnné s názvem printDoc a PrintPage zpracování událostí QueryPageSettings . Proměnná currentPageNumber se zvýší po vytištění každé stránky v PrintPage události, která se nezobrazí.

V tomto příkladu použijte obory System.Drawing názvů a System.Drawing.Printing obory názvů.

private:
   void MyButtonPrint_OnClick( Object^ sender, System::EventArgs^ e )
   {
      // Set the printer name and ensure it is valid. If not, provide a message to the user.
      printDoc->PrinterSettings->PrinterName = "\\mynetworkprinter";
      if ( printDoc->PrinterSettings->IsValid )
      {
         // If the printer supports printing in color, then override the printer's default behavior.
         if ( printDoc->PrinterSettings->SupportsColor )
         {
            // Set the page default's to not print in color.
            printDoc->DefaultPageSettings->Color = false;
         }

         // Provide a friendly name, set the page number, and print the document.
         printDoc->DocumentName = "My Presentation";
         currentPageNumber = 1;
         printDoc->Print();
      }
      else
      {
         MessageBox::Show( "Printer is not valid" );
      }
   }

   void MyPrintQueryPageSettingsEvent( Object^ sender, QueryPageSettingsEventArgs^ e )
   {
      // Determines if the printer supports printing in color.
      if ( printDoc->PrinterSettings->SupportsColor )
      {
         // If the printer supports color printing, use color.
         if ( currentPageNumber == 1 )
         {
            e->PageSettings->Color = true;
         }
      }
   }

private void MyButtonPrint_OnClick(object sender, System.EventArgs e)
{
    
    // Set the printer name and ensure it is valid. If not, provide a message to the user.
    printDoc.PrinterSettings.PrinterName = "\\mynetworkprinter";

    if (printDoc.PrinterSettings.IsValid) {
    
        // If the printer supports printing in color, then override the printer's default behavior.
        if (printDoc.PrinterSettings.SupportsColor) {

            // Set the page default's to not print in color.
            printDoc.DefaultPageSettings.Color = false;
        }

        // Provide a friendly name, set the page number, and print the document.
        printDoc.DocumentName = "My Presentation";
        currentPageNumber = 1;
        printDoc.Print();
    }
    else {
        MessageBox.Show("Printer is not valid");
    }
}

private void MyPrintQueryPageSettingsEvent(object sender, QueryPageSettingsEventArgs e)
{
    // Determines if the printer supports printing in color.
    if (printDoc.PrinterSettings.SupportsColor) {

        // If the printer supports color printing, use color.
        if (currentPageNumber == 1 ) {

            e.PageSettings.Color = true;
        }
    }    
}

Private Sub MyButtonPrint_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)

    ' Set the printer name and ensure it is valid. If not, provide a message to the user.
    printDoc.PrinterSettings.PrinterName = "\\mynetworkprinter"

    If printDoc.PrinterSettings.IsValid Then

        ' If the printer supports printing in color, then override the printer's default behavior.
        if printDoc.PrinterSettings.SupportsColor then

            ' Set the page default's to not print in color.
            printDoc.DefaultPageSettings.Color = False
        End If

        ' Provide a friendly name, set the page number, and print the document.
        printDoc.DocumentName = "My Presentation"
        currentPageNumber = 1
        printDoc.Print()
    Else
        MessageBox.Show("Printer is not valid")
    End If
End Sub

Private Sub MyPrintQueryPageSettingsEvent(ByVal sender As Object, ByVal e As QueryPageSettingsEventArgs)

    ' Determines if the printer supports printing in color.
    If printDoc.PrinterSettings.SupportsColor Then

        ' If the printer supports color printing, use color.
        If currentPageNumber = 1 Then

            e.PageSettings.Color = True
        End If

    End If
End Sub

Poznámky

Každou stránku dokumentu je možné vytisknout pomocí jiného nastavení stránky. Nastavení stránky můžete nastavit úpravou jednotlivých vlastností QueryPageSettingsEventArgs.PageSettings vlastnosti nebo nastavením vlastnosti na hodnotu PageSettings. Změny provedené pouze PageSettings na aktuální stránce, nikoli výchozí nastavení stránky dokumentu. Tiskovou úlohu lze také zrušit nastavením Cancel vlastnosti true na QueryPageSettingsEventArgshodnotu .

Pokud chcete událost přidružit k obslužné rutině události, přidejte do události instanci QueryPageSettingsEventHandler delegáta. Obslužná rutina události se volá vždy, když dojde k události. Další informace o zpracování událostí s delegáty naleznete v tématu Zpracování a vyvolávání událostí.

Pokud k úpravě nastavení tiskárny použijete QueryPageSettings událost, výkon PrintPreviewDialog ovládacího prvku se nezlepší ani v případě, že je nastavený přepínač konfigurace optimalizace. Další informace naleznete v tématu PrintPreviewDialog přehled ovládacího prvku.

Platí pro

Viz také