PrintDocument.QueryPageSettings イベント

定義

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 

イベントの種類

次のコード例では、プリンターでサポートされている場合は、最初のページの色で文書を印刷します。 この例では、 という名前printDocPrintDocument変数が作成され、 イベントと QueryPageSettingsPrintPage イベントが処理されている必要があります。 変数は currentPageNumber 、表示されないイベントで各ページが出力された後に PrintPage インクリメントされます。

この例では、 System.Drawing 名前空間と System.Drawing.Printing 名前空間を使用します。

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

注釈

異なるページ設定を使用して、ドキュメントの各ページを印刷できます。 ページ設定を設定するには、 プロパティの個々のプロパティを QueryPageSettingsEventArgs.PageSettings 変更するか、 プロパティを に PageSettings設定します。 に加えられた変更は PageSettings 、ドキュメントの既定のページ設定ではなく、現在のページにのみ影響します。 印刷ジョブは、 の プロパティを CanceltrueQueryPageSettingsEventArgs設定することで取り消すこともできます。

イベントをイベント ハンドラーに関連付けるには、デリゲートのインスタンスを QueryPageSettingsEventHandler イベントに追加します。 イベント ハンドラーは、イベントが発生するたびに呼び出されます。 デリゲートを使用したイベントの処理の詳細については、「イベントの 処理と発生」を参照してください。

プリンターの設定を QueryPageSettings イベントを使用して変更した場合、構成の最適化スイッチが設定されていても、PrintPreviewDialog コントロールのパフォーマンスは向上しません。 詳細については、「PrintPreviewDialog コントロールの概要」を参照してください。

適用対象

こちらもご覧ください