diff --git a/samples/snippets/csharp/VS_Snippets_Winforms/PaperSource and PaperSize Example with Resolution/CS/source.cs b/samples/snippets/csharp/VS_Snippets_Winforms/PaperSource and PaperSize Example with Resolution/CS/source.cs index c31a581ea16..90fa8dcfe88 100644 --- a/samples/snippets/csharp/VS_Snippets_Winforms/PaperSource and PaperSize Example with Resolution/CS/source.cs +++ b/samples/snippets/csharp/VS_Snippets_Winforms/PaperSource and PaperSize Example with Resolution/CS/source.cs @@ -6,6 +6,7 @@ using System.ComponentModel; using System.Windows.Forms; using System.Data; +using System.Runtime.InteropServices; namespace WindowsApplication3 { @@ -283,8 +284,15 @@ private void MyButtonPrint_Click(object sender, System.EventArgs e) protected int currentPageNumber = 1; // - private void MyButtonPrint_OnClick(object sender, System.EventArgs e) - { + [DllImport("winspool.drv", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)] + private static extern int DeviceCapabilitiesW(string pDevice, string pPort, short fwCapabilities, IntPtr pOutput, IntPtr pDevMode); + private const short DC_COLORDEVICE = 32; + + private static bool GetColorDeviceCapability(string printerName) { + return DeviceCapabilitiesW(printerName, null, DC_COLORDEVICE, IntPtr.Zero, IntPtr.Zero) == 1; + } + + 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"; @@ -292,7 +300,7 @@ private void MyButtonPrint_OnClick(object sender, System.EventArgs e) if (printDoc.PrinterSettings.IsValid) { // If the printer supports printing in color, then override the printer's default behavior. - if (printDoc.PrinterSettings.SupportsColor) { + if (GetColorDeviceCapability("\\mynetworkprinter")) { // Set the page default's to not print in color. printDoc.DefaultPageSettings.Color = false; diff --git a/xml/System.Drawing.Printing/PrinterSettings.xml b/xml/System.Drawing.Printing/PrinterSettings.xml index fa06153c126..9a5511ae674 100644 --- a/xml/System.Drawing.Printing/PrinterSettings.xml +++ b/xml/System.Drawing.Printing/PrinterSettings.xml @@ -1654,13 +1654,16 @@ System.Boolean - Gets a value indicating whether this printer supports color printing. + On .NET Frameworks 1.1 to 4.8, .NET Core framework versions 3.1 and 3.0, and on .NET Framework Extensions 2.1 to 3.1, gets a value indicating whether this printer uses multiple adjacent color bits for each pixel. This value does not guarantee if this printer supports color.
+ On .NET 5, gets a value indicating whether this printer supports color printing.
- if this printer supports color; otherwise, . + On versions below .NET 5, if this printer uses multiple adjacent color bits for each pixel; otherwise, . + On .NET 5 and above, if this printer supports color; otherwise, . To print using color, and if the printer supports it, set to `true`. @@ -1672,7 +1675,7 @@ [!code-cpp[PaperSource and PaperSize Example with Resolution#6](~/samples/snippets/cpp/VS_Snippets_Winforms/PaperSource and PaperSize Example with Resolution/CPP/source.cpp#6)] [!code-csharp[PaperSource and PaperSize Example with Resolution#6](~/samples/snippets/csharp/VS_Snippets_Winforms/PaperSource and PaperSize Example with Resolution/CS/source.cs#6)] - [!code-vb[PaperSource and PaperSize Example with Resolution#6](~/samples/snippets/visualbasic/VS_Snippets_Winforms/PaperSource and PaperSize Example with Resolution/VB/source.vb#6)] + [!code-vb[PaperSource and PaperSize Example with Resolution#6](~/samples/snippets/visualbasic/VS_Snippets_Winforms/PaperSource and PaperSize Example with Resolution/VB/source.vb#6)] ]]>