如何使用C#里面的打印技术

C#code

private void Print1_Click_1(object sender, EventArgs e)
        {
            PrintDocument pd = new PrintDocument();
            Margins margin = new Margins(20,20,20,20);
            pd.DefaultPageSettings.Margins = margin;
            PaperSize pagesize = new PaperSize("First custom size",400,240);
           
            pd.DefaultPageSettings.PaperSize = pagesize;
            pd.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);
            try
            {
                //pd.Print();
                this.printPreviewDialog1.Document = this.printDocument1;

                this.printPreviewDialog1.ShowDialog();
            }
            catch
            {
                throw new UserEmployeeException("请检查是否已连接到打印机");
            }
        }

 private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
           
            e.Graphics.DrawString("天津农学院处方便签",new Font("宋体",12,FontStyle.Bold),Brushes.Black,180,11 );
            e.Graphics.DrawLine(new Pen(Color.Black),0,40,500,40);
            e.Graphics.DrawString("姓名:" + nameBox.Text,new Font("宋体",9),Brushes.Black,10, 50);
            e.Graphics.DrawString("年龄:"+ageBox.Text,new Font("宋体",9),Brushes.Black,100,50);
            e.Graphics.DrawString("性别:" + sexBox.Text, new Font("宋体", 9), Brushes.Black, 180, 50);
            e.Graphics.DrawString("日期:" + DateTime.Now.ToString(), new Font("宋体", 9), Brushes.Black, 260, 50);
            e.Graphics.DrawString("诊断:"+diagnoseBox.Text , new Font("宋体", 9), Brushes.Black, 10, 90);
            e.Graphics.DrawString("地址:" + addressBox.Text, new Font("宋体", 9), Brushes.Black, 180, 90);
            e.Graphics.DrawLine(new Pen(Color.Black), 0, 110, 500, 110);
            e.Graphics.DrawString("Rp", new Font("宋体", 12,FontStyle.Bold), Brushes.Black, 10, 120);
            e.Graphics.DrawString(imformationBox.Text, new Font("宋体", 9), Brushes.Black, 40, 100);
            e.Graphics.DrawLine(new Pen(Color.Black), 0, 700, 500, 700);
            e.Graphics.DrawRectangle(new Pen(Color.Black), 30, 720,80,50);
            e.Graphics.DrawString("划价" , new Font("宋体", 12), Brushes.Black, 50, 735);
            e.Graphics.DrawRectangle(new Pen(Color.Black), 110, 720,80,50);
            e.Graphics.DrawString(costBox.Text, new Font("宋体", 12), Brushes.Black, 140, 715);
            e.Graphics.DrawString("收费/n盖章", new Font("宋体", 14), Brushes.Black, 250, 725);
            e.Graphics.DrawString("医生:"+doctorBox.Text, new Font("宋体", 10), Brushes.Black, 320, 725);
            e.Graphics.DrawString("配药:" + matchBox.Text, new Font("宋体", 10), Brushes.Black, 320, 750);
            e.Graphics.DrawLine(new Pen(Color.Black), 0, 800, 500, 800);
            //e.MarginBounds
;        }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值