locked
Print to a Specific Printer RRS feed

  • Question

  • Hi,

    I have 3 local printers on my PC, 2 HPs and one Canon and I want to print from my C# Windows application only to the canon so I need to set the print in my application then send any print to that printer.

    How can I do this please?

    Thanks,

    Jassim

    Saturday, October 17, 2015 12:35 PM

Answers

  • It's C# WinForm

    Hi Jassim,

    The following sample is winform but always prints to default printer

    PrintDialog pdlg = new PrintDialog();
    
    // Show the PrintDialog
    if (pdlg.ShowDialog() == DialogResult.OK)
    {
       PrintDocument pd = new PrintDocument();
       pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
    
       // Associate PrintDocument object with the PrintDialog
       pdlg.Document = pd;
    
       // Print with the new PrinterSettings
       pd.Print();
    }

    Considering your issue is that regarding print to a specific printer, You need to assign the PrintDocument to the PrintDialog before you call ShowDialog().

    Using the PrintDocument component and select the printer from PrinterSettings.InstalledPrinters.

    Please also refer to the following  thread

    Printing problem in C# windows app - Always prints to default printer

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, October 19, 2015 2:53 AM

All replies

  • The .Net BCL does not support printing. Answers to your question varies based on what you are writing e.g. WPF, Winforms, Windows Store etc. Better just search the forum most relevant to your question with the keyword "select printer" and save yourself the time typing a new question. 


    Visual C++ MVP

    Saturday, October 17, 2015 3:08 PM
  • It's C# WinForm
    Saturday, October 17, 2015 4:20 PM
  • It's C# WinForm

    Hi Jassim,

    The following sample is winform but always prints to default printer

    PrintDialog pdlg = new PrintDialog();
    
    // Show the PrintDialog
    if (pdlg.ShowDialog() == DialogResult.OK)
    {
       PrintDocument pd = new PrintDocument();
       pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
    
       // Associate PrintDocument object with the PrintDialog
       pdlg.Document = pd;
    
       // Print with the new PrinterSettings
       pd.Print();
    }

    Considering your issue is that regarding print to a specific printer, You need to assign the PrintDocument to the PrintDialog before you call ShowDialog().

    Using the PrintDocument component and select the printer from PrinterSettings.InstalledPrinters.

    Please also refer to the following  thread

    Printing problem in C# windows app - Always prints to default printer

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, October 19, 2015 2:53 AM