当前位置:编程学习 > C#/ASP.NET >>

求CSDN的各位大神帮我看看

   private void btnPrint_Click(object sender, EventArgs e)
        {
            try
            {
                //以tbJB这个文本框的值来查找脚本文件
                string strline;
                FileStream afile = new FileStream("" + tbJB.Text + "", FileMode.Open);
                //MessageBox.Show("当前打开的文件"+tbJB.Text);
                StreamWriter sw = new StreamWriter(afile);

                //读取脚本文件并用界面的值替换脚本中对应的变量
                StreamReader sr = new StreamReader(afile);
                strline = sr.ReadToEnd();
                sw.Close();
                string a = strline;

                a = a.Replace("$QSSN$", this.tbSN.Text);
                a = a.Replace("$FLASH$", this.tbFlash.Text);
                a = a.Replace("$PD$", this.cbPD.Text);
                a = a.Replace("$JZ$", this.tbJZ.Text);
                a = a.Replace("$SL$", this.tbSL.Text);
                //a = a.Replace("$HW$", this.textBox2.Text);
                //a = a.Replace("$SW$", this.textBox4.Text);
                //a = a.Replace("$WEEK$", this.label10.Text);
                //a = a.Replace("$YEAR$", DateTime.Now.Year.ToString().Remove(0, 2));



                FileStream bfile = new FileStream("label17.txt", FileMode.Create);
                StreamWriter ssw = new StreamWriter(bfile);
                ssw.WriteLine(a);

                ssw.Close();

                //把脚本推送到打印机
                Process p = new Process();

                p.StartInfo.FileName = "cmd.exe";

                p.StartInfo.UseShellExecute = false;

                p.StartInfo.RedirectStandardInput = true;

                p.StartInfo.RedirectStandardOutput = true;

                p.StartInfo.RedirectStandardError = true;

                p.StartInfo.CreateNoWindow = true;

                string pingrst;
                p.Start();

                p.StandardInput.WriteLine("copy label.txt lpt1");

                p.StandardInput.WriteLine("exit");

                string strRst = p.StandardOutput.ReadToEnd();

                if (strRst.IndexOf("(0% loss)") != -1)
                {
                    pingrst = "连接";
                }

                else if (strRst.IndexOf("Destination host unreachable.") != -1)
                {
                    pingrst = "无法到达目的主机";
                }

                else if (strRst.IndexOf("Request timed out.") != -1)
                {
                    pingrst = "超时";
                }
                else if (strRst.IndexOf("Unknown host") != -1)
                {
                    pingrst = "无法解析主机";
                }
                else
                {
                    pingrst = strRst;
                }
                p.Close();
                MessageBox.Show("打印完成!");
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.ToString().Trim());
            }
        }
这是我写的打印,但是现在有点问题请教各位 因为想在有两台打印我都要使用 但是 我写的 只能通过其中一台打印机打印,我请各位大神帮我改造下代码 让这段代码可以通过不同的打印端口打印  两台打印机的端口 分别为LPT1  LPT3 --------------------编程问答-------------------- 打印机。。。。没做过,mark一下,留着以后学习 --------------------编程问答-------------------- api函数SetDefaultPrinter设置默认打印机 --------------------编程问答-------------------- 我现在问题的根源在 我这段代码只能通过系统默认打印机打印  我现在 要用两台打印机 我想在这段代码中加一段 来指定这个打印端口  然后运行的时候就会找到我指定的端口来打印 --------------------编程问答--------------------
引用 2 楼 bdmh 的回复:
api函数SetDefaultPrinter设置默认打印机

我现在问题的根源在 我这段代码只能通过系统默认打印机打印  我现在 要用两台打印机 我想在这段代码中加一段 来指定这个打印端口  然后运行的时候就会找到我指定的端口来打印  --------------------编程问答--------------------
引用 4 楼 ak3219033vip 的回复:
引用 2 楼 bdmh 的回复:api函数SetDefaultPrinter设置默认打印机
我现在问题的根源在 我这段代码只能通过系统默认打印机打印  我现在 要用两台打印机 我想在这段代码中加一段 来指定这个打印端口  然后运行的时候就会找到我指定的端口来打印

参考这个 --------------------编程问答--------------------
引用 5 楼 chb345536638 的回复:
引用 4 楼 ak3219033vip 的回复:
引用 2 楼 bdmh 的回复:api函数SetDefaultPrinter设置默认打印机
我现在问题的根源在 我这段代码只能通过系统默认打印机打印  我现在 要用两台打印机 我想在这段代码中加一段 来指定这个打印端口  然后运行的时候就会找到我指定的端口来打印
参考这个

我看了 和我的不一样啊 我现在是不知道怎么来给我的打印部分指定一个端口打印也可以说是指定一个打印机打印  你帮我改造下我这段代码好吧
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,