PrintDocument.QueryPageSettings Evento

Definizione

Si verifica immediatamente prima di ogni evento PrintPage.

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 

Tipo evento

Esempio

Nell'esempio di codice seguente viene stampato un documento con la prima pagina a colori, se la stampante la supporta. L'esempio richiede che sia stata creata una PrintDocument variabile denominata printDoc e che gli PrintPage eventi e QueryPageSettings vengano gestiti. La currentPageNumber variabile viene incrementata dopo la stampa di ogni pagina nell'evento PrintPage , che non viene visualizzata.

Usare gli spazi dei System.Drawing nomi e System.Drawing.Printing per questo esempio.

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

Commenti

È possibile stampare ogni pagina di un documento utilizzando impostazioni di pagina diverse. È possibile impostare le impostazioni della pagina modificando le singole proprietà della QueryPageSettingsEventArgs.PageSettings proprietà o impostando la proprietà su un oggetto PageSettings. Le modifiche apportate all'oggetto PageSettings influiscono solo sulla pagina corrente, non sulle impostazioni predefinite della pagina del documento. È anche possibile annullare il processo di stampa impostando la Cancel proprietà su true per .QueryPageSettingsEventArgs

Per associare l'evento al gestore eventi, aggiungere un'istanza del QueryPageSettingsEventHandler delegato all'evento. Il gestore eventi viene chiamato ogni volta che si verifica l'evento. Per altre informazioni sulla gestione degli eventi con delegati, vedere Gestione e generazione di eventi.

Se si utilizza l'evento QueryPageSettings per modificare le impostazioni della stampante, le prestazioni del PrintPreviewDialog controllo non miglioreranno anche se è impostato un commutatore di configurazione di ottimizzazione. Per altre informazioni, vedere Cenni preliminari sul controllo PrintPreviewDialog.

Si applica a

Vedi anche