PageSettings.Color 属性

定义

获取或设置一个值,该值指示是否应以彩色打印该页。Gets or sets a value indicating whether the page should be printed in color.

public:
 property bool Color { bool get(); void set(bool value); };
public bool Color { get; set; }
member this.Color : bool with get, set
Public Property Color As Boolean

属性值

Boolean

如果该页应以彩色打印,则为 true;反之,则为 falsetrue if the page should be printed in color; otherwise, false. 默认值由打印机决定。The default is determined by the printer.

例外

PrinterName 属性中命名的打印机不存在。The printer named in the PrinterName property does not exist.

示例

下面的代码示例使用颜色打印第一页,如果打印机支持该文档。The following code example prints a document with the first page in color, if the printer supports it. 该示例需要创建一个 PrintDocument 名为的变量 printDoc ,并 PrintPage QueryPageSettings 处理和事件。The example requires that a PrintDocument variable named printDoc has been created, and the PrintPage and QueryPageSettings events are handled.

System.Drawing System.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

注解

您可以使用 PrinterSettings.SupportsColor 属性来确定打印机是否支持彩色打印。You can use the PrinterSettings.SupportsColor property to determine if the printer supports color printing. 如果打印机支持颜色,但您不希望以彩色打印,请将 Color 属性设置为 falseIf the printer supports color, but you do not want to print in color, set the Color property to false. 默认值为 trueThe default will be true.

适用于

另请参阅