默认打印机打印

 上面是控件选择,下面直接上代码,打印是默认打印机打印

namespace WinfromPrint
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        #region 定义全局变量及对象
        Brush myBrush = new SolidBrush(Color.Black);
        Pen mypen = new Pen(Color.Black);
        Font myFont = new Font("宋体", 13);
        #endregion

        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            pageSetupDialog1.PageSettings.Landscape = true;
            printPreviewDialog1.ShowDialog();  
          
        }

        private void printDocument1_PrintPage_1(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            
            this.Hide();
    

            int printWidth = e.PageBounds.Width;
            int printHeight = e.PageBounds.Height;
            //左侧
            e.Graphics.DrawString("附件", new Font("宋体", 17, FontStyle.Bold), myBrush, 50, 50);
            e.Graphics.DrawString("道路货运运单", new Font("宋体", 16, FontStyle.Bold), myBrush, 200, 100);
            e.Graphics.DrawString("(存根联)", new Font("宋体", 14), myBrush,265, 135);
            e.Graphics.DrawString("运单编号:", new Font("宋体", 12,FontStyle.Bold), myBrush, 162, 160);
            e.Graphics.DrawString("货物装载源头单位:(盖章)", new Font("宋体", 13), myBrush, 120, 220);
            e.Graphics.DrawString("货物装载源头单位联系电话:", new Font("宋体", 13), myBrush, 120, 250);
            e.Graphics.DrawString("车辆号牌:__________(黄)", new Font("宋体", 13), myBrush, 120, 280);
            e.Graphics.DrawString("车辆道路运输证号:", new Font("宋体", 13), myBrush, 120, 310);
            e.Graphics.DrawString("挂车号牌:__________(黄)", new Font("宋体", 13), myBrush, 120, 340);
            e.Graphics.DrawString("挂车道路运输证号:", new Font("宋体", 13), myBrush, 120, 370);
            e.Graphics.DrawString("轴型:_____轴;车货总质量限值:______吨", new Font("宋体", 12), myBrush, 120, 400);
            e.Graphics.DrawString("驾驶员姓名:", new Font("宋体", 13), myBrush, 120, 430);
            e.Graphics.DrawString("驾驶员从业资格证:", new Font("宋体", 13), myBrush, 120, 460);
            e.Graphics.DrawString("货物品种:", new Font("宋体", 13), myBrush, 120, 490);
            e.Graphics.DrawString("车货总重:___________吨", new Font("宋体", 13), myBrush, 120, 520);
            e.Graphics.DrawString("起运地:", new Font("宋体", 13), myBrush, 120, 550);
            e.Graphics.DrawString("托运单位:", new Font("宋体", 13), myBrush, 120, 580);
            e.Graphics.DrawString("送达地:", new Font("宋体", 13), myBrush, 120, 610);
            e.Graphics.DrawString("收货单位:", new Font("宋体", 13), myBrush, 120, 640);
    
           //填充右侧内容
           
            e.Graphics.DrawString("道路货运运单", new Font("宋体", 16, FontStyle.Bold), myBrush, 750, 100);
            e.Graphics.DrawString("(随车备查联)", new Font("宋体", 14), myBrush, 800, 135);
            e.Graphics.DrawString("运单编号:", new Font("宋体", 12, FontStyle.Bold), myBrush, 680, 160);
            e.Graphics.DrawString("货物装载源头单位:(盖章)", myFont, myBrush, 620, 220);
            e.Graphics.DrawString("货物装载源头单位联系电话:", myFont, myBrush, 620, 250);
            e.Graphics.DrawString("车辆号牌:__________(黄)", myFont, myBrush, 620, 280);
            e.Graphics.DrawString("车辆道路运输证号:", myFont, myBrush, 620, 310);
            e.Graphics.DrawString("挂车号牌:__________(黄)", myFont, myBrush, 620, 340);
            e.Graphics.DrawString("挂车道路运输证号:", myFont, myBrush, 620, 370);
            e.Graphics.DrawString("轴型:_____轴;车货总质量限值:______吨", myFont, myBrush, 620, 400);
            e.Graphics.DrawString("驾驶员姓名:", myFont, myBrush, 620, 430);
            e.Graphics.DrawString("驾驶员从业资格证:", myFont, myBrush, 620, 460);
            e.Graphics.DrawString("货物品种:", myFont, myBrush, 620, 490);
            e.Graphics.DrawString("车货总重:___________吨", myFont, myBrush, 620, 520);
            e.Graphics.DrawString("起运地:", myFont, myBrush, 620, 550);
            e.Graphics.DrawString("托运单位:", myFont, myBrush, 620, 580);
            e.Graphics.DrawString("送达地:", myFont, myBrush, 620, 610);
            e.Graphics.DrawString("收货单位:", myFont, myBrush, 620, 640);


        }
    }
}

下面是打印预览图

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值