J'ai trouvé une solution avec le DEVMODE et quelques pInvokes; Devmode: (http://msdn.microsoft.com/en-us/library/aa927408.aspx) Cette structure contient des informations sur l'environnement de l'imprimante et l'initialisation du périphérique.
Il contient un champ: dmColor (court) en réglant ceci sur 1 signifie échelle de gris/monochrome, ce réglage sur 2 signifie couleur. La modification de ces paramètres affecte directement l'imprimante et remplace les paramètres utilisateur.
[DllImport ("Winspool.drv", charset = CharSet.Ansi, SetLastError = true)]
extern private static bool SetPrinter (IntPtr hPrinter, int Niveau, IntPtr pPrinter, commande int);
I used this example to create my code
public bool setPrinterToGrayScale(string printerName)
{
short monochroom = 1;
dm = this.GetPrinterSettings(printerName);
dm.dmColor = monochroom;
Marshal.StructureToPtr(dm, yDevModeData, true);
pinfo.pDevMode = yDevModeData;
pinfo.pSecurityDescriptor = IntPtr.Zero;
Marshal.StructureToPtr(pinfo, ptrPrinterInfo, true);
lastError = Marshal.GetLastWin32Error();
nRet = Convert.ToInt16(SetPrinter(hPrinter, 2, ptrPrinterInfo, 0));
if (nRet == 0)
{
//Unable to set shared printer settings.
lastError = Marshal.GetLastWin32Error();
//string myErrMsg = GetErrorMessage(lastError);
throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
}
if (hPrinter != IntPtr.Zero)
ClosePrinter(hPrinter);
return Convert.ToBoolean(nRet);
}
PrinterName peut être récupéré via:
System.Drawing.Printing.PrinterSettings.InstalledPrinters