PrintDocument.DocumentName プロパティ

定義

ドキュメントの印刷中に、印刷ステータス ダイアログ ボックスやプリンター キューなどで表示するドキュメントの名前を取得または設定します。Gets or sets the document name to display (for example, in a print status dialog box or printer queue) while printing the document.

public:
 property System::String ^ DocumentName { System::String ^ get(); void set(System::String ^ value); };
public string DocumentName { get; set; }
member this.DocumentName : string with get, set
Public Property DocumentName As String

プロパティ値

String

ドキュメントの印刷中に表示するドキュメント名。The document name to display while printing the document. 既定値は "document" です。The default is "document".

次のコード例では、最初のページを使用してドキュメントを印刷します。プリンターがサポートしている場合は、DocumentName をユーザーフレンドリ名に設定します。The following code example prints a document with the first page in color, if the printer supports it, and sets the DocumentName to a user-friendly name. この例では、printDoc という名前の PrintDocument 変数が作成され、PrintPage イベントと QueryPageSettings イベントが処理される必要があります。The example requires that a PrintDocument variable named printDoc has been created, and the PrintPage and QueryPageSettings events are handled.

この例では、System.DrawingSystem.Drawing.Printing 名前空間を使用します。Use the System.Drawing and System.Drawing.Printing namespaces for this example.

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

注釈

DocumentName プロパティでは、印刷するファイルが指定されていません。The DocumentName property does not specify the file to print. 代わりに、PrintPage イベントを処理することによって出力を指定します。Rather, you specify the output to print by handling the PrintPage event. 例については、「PrintDocument クラスの概要」を参照してください。For an example, see the PrintDocument class overview.

適用対象

こちらもご覧ください