Marco Dinatsoli
Marco Dinatsoli

Reputation: 10570

How to print to a network printer with IP address

I have finished an app that using printer.

this is code of printing:

this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.printDialog1 = new System.Windows.Forms.PrintDialog();
printDocument1.PrintPage += printDocument1_PrintPage;
this.printDocument1.Print();

now I have a printer named XXX, and which has IP address 192.168.2.200

My question

how can I print to that printer please?

Thanks

Update

this.printDocument1 = new System.Drawing.Printing.PrintDocument();
            this.printDocument1.PrinterSettings.PrinterName = "MainPass";
            this.printDialog1 = new System.Windows.Forms.PrintDialog();
            printDocument1.PrintPage += printDocument1_PrintPage;
                this.printDocument1.Print();

and then the printDocument1_PrintPage is :

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawString("PANTRY KOY", valueFont, Brushes.Black, width, height);


            printDialog1.Document = printDocument1;
}

Upvotes: 0

Views: 3160

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 415600

If you have a PrintDialog instance, that implies you are letting the user select a printer, and you need to respect the printer chosen there. (hint: you can set the initial printer shown in the dialog, through the PrinterName property of the dialog's PrintSettings property). After that, I bet that if you scan through the documentation for the PrintDocument Properties, you'll see what you need to do to set the printer (hint: the IP Address doesn't matter, but the PrinterName does).

Upvotes: 1

Related Questions