PrintDocument.DocumentName Właściwość

Definicja

Pobiera lub ustawia nazwę dokumentu do wyświetlenia (na przykład w oknie dialogowym stanu wydruku lub w kolejce drukarki) podczas drukowania dokumentu.

C#
public string DocumentName { get; set; }

Wartość właściwości

Nazwa dokumentu do wyświetlenia podczas drukowania dokumentu. Wartość domyślna to "dokument".

Przykłady

Poniższy przykład kodu drukuje dokument z pierwszą stroną w kolorze, jeśli drukarka go obsługuje, i ustawia DocumentName na przyjazną nazwę użytkownika. Przykład wymaga PrintDocument utworzenia zmiennej o nazwie printDoc , a PrintPage zdarzenia i QueryPageSettings są obsługiwane.

W tym przykładzie System.Drawing użyj przestrzeni nazw i System.Drawing.Printing .

C#

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;
        }
    }    
}

Uwagi

Właściwość DocumentName nie określa pliku do wydrukowania. Zamiast tego należy określić dane wyjściowe do wydrukowania, obsługując PrintPage zdarzenie. Aby zapoznać się z przykładem, zobacz PrintDocument omówienie klasy.

Dotyczy

Produkt Wersje
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Zobacz też