一台电脑上有2台打印机。想在程序实现打印不同的信息自动切换到相应的打印机。
PrintDocument m_printDocument = new PrintDocument();m_printDocument.PrinterSettings.PrinterName = "ZDesigner S4M-203dpi ZPL (1)";我这里写也没反应的!
在此先感谢各位了!

解决方案 »

  1.   

    你要通过Print Dialog 获取打印机的名称,然后通过下面的方法设置打印机
    crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage);

    下面是示例代码:
    private void button2_Click(object sender, System.EventArgs e)
    {
        //Open the PrintDialog    this.printDialog1.Document = this.printDocument1;
        DialogResult dr = this.printDialog1.ShowDialog();
        if(dr == DialogResult.OK)
        {
            //Get the Copy times        int nCopy = this.printDocument1.PrinterSettings.Copies;
            //Get the number of Start Page        int sPage = this.printDocument1.PrinterSettings.FromPage;
            //Get the number of End Page        int ePage = this.printDocument1.PrinterSettings.ToPage;
            //Get the printer name        string PrinterName = this.printDocument1.PrinterSettings.PrinterName;        crReportDocument = new ReportDocument();
            //Create an instance of a report        crReportDocument = new Chart();
            try
            {
                //Set the printer name to print the report to. By default the sample            //report does not have a defult printer specified. This will tell the            //engine to use the specified printer to print the report. Print out             //a test page (from Printer properties) to get the correct value.
                crReportDocument.PrintOptions.PrinterName = PrinterName;
                //Start the printing process. Provide details of the print job            //using the arguments.            crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage);            //Let the user know that the print job is completed            MessageBox.Show("Report finished printing!");
            }
            catch(Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }
    }
      

  2.   

    string name=this.printDialog1.PrinterSettings.PrinterName;
    printDocument1.PrinterSettings.PrinterName = name;
    printDialog1.Document = printDocument1;
    printDocument1.Print();printdialog1.Name//读取打印机的名称