PrintDocument.QueryPageSettings Evento

Definição

Ocorre imediatamente antes de cada 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 de evento

Exemplos

O exemplo de código a seguir imprime um documento com a primeira página em cores, se a impressora der suporte a ele. O exemplo requer que uma PrintDocument variável chamada printDoc tenha sido criada e os PrintPage eventos e QueryPageSettings sejam tratados. A currentPageNumber variável é incrementada depois que cada página é impressa no evento, o PrintPage que não é mostrado.

Use os System.Drawing namespaces e System.Drawing.Printing para este exemplo.

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

Comentários

É possível imprimir cada página de um documento usando configurações de página diferentes. Defina as configurações de página modificando propriedades individuais da QueryPageSettingsEventArgs.PageSettings propriedade ou definindo a propriedade como um PageSettings. As alterações feitas no PageSettings afetam apenas a página atual, não as configurações de página padrão do documento. O trabalho de impressão também pode ser cancelado definindo a Cancel propriedade true como para o QueryPageSettingsEventArgs.

Para associar o evento ao manipulador de eventos, adicione uma instância do QueryPageSettingsEventHandler delegado ao evento. O manipulador de eventos é chamado sempre que o evento ocorre. Para obter mais informações sobre como lidar com eventos com delegados, consulte Manipulando e gerando eventos.

Se você usar o QueryPageSettings evento para modificar as configurações da impressora, o PrintPreviewDialog desempenho do controle não melhorará mesmo se uma opção de configuração de otimização estiver definida. Para obter mais informações, consulte Visão geral do controle PrintPreviewDialog.

Aplica-se a

Confira também