打印代码

来源:互联网 发布:国信金太阳软件下载 编辑:程序博客网 时间:2024/06/05 15:21

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

  private void button1_Click(object sender, EventArgs e)
  {
   PrintDocument pd = new PrintDocument();
   pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
   
   //if (this.storePageSettings != null)
   //{
   //    pd.DefaultPageSettings = this.storePageSettings;
   //}
   PrintDialog dlg = new PrintDialog();
   dlg.Document = pd;
   if (dlg.ShowDialog() == DialogResult.OK)
   {
    pd.Print();
   }

  }

  void pd_PrintPage(object sender, PrintPageEventArgs e)
  {
   Graphics g = e.Graphics;
   PaintDocument(g);
   e.HasMorePages = false;

  }

  /// <summary>
  /// 打印输出定位
  /// </summary>
  /// <param ></param>
  private void PaintDocument(Graphics g)
  {
   g.PageUnit = GraphicsUnit.Point;
   //出口口岸
   g.DrawString("订单打印测试", new Font("Arial",42,FontStyle.Bold), Brushes.Black, new Point(0, 500));//POINT定位

  }
 }
}

原创粉丝点击