Export (0) Print
Expand All

PrintDocument.DocumentName Property

Gets or sets the document name to display (for example, in a print status dialog box or printer queue) while printing the document.

Namespace:  System.Drawing.Printing
Assembly:  System.Drawing (in System.Drawing.dll)

Public Property DocumentName As String

Property Value

Type: System.String
The document name to display while printing the document. The default is "document".

The DocumentName property does not specify the file to print. Rather, you specify the output to print by handling the PrintPage event. For an example, see the PrintDocument class overview.

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. The example requires that a PrintDocument variable named printDoc has been created, and the PrintPage and QueryPageSettings events are handled.

Use the System.Drawing and System.Drawing.Printing namespaces for this example.

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft