踏雪寻梅 发表于 2017-4-20 11:35:43

实现打印机

Font a=new Font("Tahoma",11,FontStyle.Regular);
      Brush s=Brushes.Black;
      Pen d=new Pen(s);

      d.Width=2;

      int nleft=this.pageSetupDialog1.PageSettings.Margins.Left;
      int ntop=this.pageSetupDialog1.PageSettings.Margins.Top;
      int nwidth=this.pageSetupDialog1.PageSettings.PaperSize.Width-(this.pageSetupDialog1.PageSettings.Margins.Left+this.pageSetupDialog1.PageSettings.Margins.Right);
      int nheight=this.pageSetupDialog1.PageSettings.PaperSize.Height-(this.pageSetupDialog1.PageSettings.Margins.Top+this.pageSetupDialog1.PageSettings.Margins.Bottom);


      e.Graphics.DrawLine(d,nleft,ntop,nleft+nwidth,ntop);
      e.Graphics.DrawLine(d,nleft,ntop+nheight,nleft+nwidth,ntop);
      e.Graphics.DrawLine(d,nleft,ntop,nleft,nleft+nheight);
      e.Graphics.DrawLine(d,nleft+nwidth,ntop,nleft+nwidth,ntop+nheight);


      e.Graphics.DrawString("订单细目数据",new Font("Garamons",40),s,nleft+30,ntop+10);
      e.Graphics.DrawString("订单细目编号",a,s,nleft+20,ntop+60);
      e.Graphics.DrawString("订单编号",a,s,nleft+140,ntop+60);
      e.Graphics.DrawString("产品编号",a,s,nleft+260,ntop+60);
      e.Graphics.DrawString("数量",a,s,nleft+340,ntop+60);
      e.Graphics.DrawString("单价",a,s,nleft+420,ntop+60);
      e.Graphics.DrawString("总价",a,s,nleft+520,ntop+60);


      e.Graphics.DrawString(this.textBox1.Text,a,s,nleft+20,ntop+30);
      e.Graphics.DrawString(this.textBox2.Text,a,s,nleft+140,ntop+30);
      e.Graphics.DrawString(this.textBox3.Text,a,s,nleft+260,ntop+30);
      e.Graphics.DrawString(this.textBox4.Text,a,s,nleft+340,ntop+30);
      e.Graphics.DrawString(this.textBox5.Text,a,s,nleft+420,ntop+30);
      e.Graphics.DrawString (this.textBox6.Text,a,s,nleft+520,ntop+30);
页: [1]
查看完整版本: 实现打印机