Change default printer c #

3

I'm working on a solution where I need to change the default printer for a label printer to print and go back to the previous default printer.

Would anyone have a solution for this?

    
asked by anonymous 30.11.2017 / 13:05

1 answer

5

It worked fine, follow the code, thanks!

     using System.Drawing.Printing;
     using System.Runtime.InteropServices;

    private void trocarImpressora()
    {
        ArrayList impressoras = new ArrayList(); 
        int i = 0;

        PrintDocument pd = new PrintDocument();
        string impressoraPadraoOriginal = pd.PrinterSettings.PrinterName;
        myPrinters.SetDefaultPrinter("ZDesigner GC420t (EPL)");
        imprimir();
        myPrinters.SetDefaultPrinter(impressoraPadraoOriginal);

    }

  public static class myPrinters
    {
        [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool SetDefaultPrinter(string Name);

    }
    
30.11.2017 / 14:13