As we learned how to list installed printers , also it is possible set printer as default at run time with some tricky C# code. This can be achieved by using winspool.drv functionality.
Firstly incorporate the Winspool functionality to C# by using DllImport.
- Add using System.Runtime.InteropServices
- Add a public class Myprinter and implement SetDefaultPrinter method (bottom of the namespace )
public static class myPrinters { [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool SetDefaultPrinter(string Name); }
Now you can simply set a printer as default using the following code.
myPrinters.SetDefaultPrinter(<yourprinter name>);
That is all for today