using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing; namespace Zsh.print
{
public partial class frmBadHzd : Form
{
public frmBadHzd()
{
InitializeComponent();
} private void frmBadHzd_Paint(object sender, PaintEventArgs e)
{
Font font;
string str;
float xPos; //x点坐标
 float yPos; //y点的坐标
  float topMargin = ;
float leftMargin = ; font = new Font("宋体", );
str = "欢迎光临";
xPos = leftMargin + ;
yPos = topMargin;
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("黑体", );
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + ;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("黑体", );
str = "客 户 回 执 单";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("黑体", );
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = " 凭单号";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = "业务类型";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = " 卡号";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = " 原余额";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = " 现余额";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("黑体", );
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + ;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = "客户签名";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + ;
yPos = yPos + font.GetHeight(e.Graphics) - ;
font = new Font("宋体", );
str = "-----------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics);
font = new Font("宋体", );
str = "受理单位名称";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = " 操作员名称";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + ;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = "   日期";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("黑体", );
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("华文行楷", );
str = "此凭单为购物凭证,请妥善保管!";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());
} private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Font font;
string str;
float xPos; //x点坐标
 float yPos; //y点的坐标
 float topMargin = ;
float leftMargin = ; font = new Font("宋体", );
str = "欢迎光临";
xPos = leftMargin + ;
yPos = topMargin;
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("黑体", );
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + ;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("黑体", );
str = "客 户 回 执 单";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("黑体", );
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = " 凭单号";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = "业务类型";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = " 卡号";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = " 原余额";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = " 现余额";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("黑体", );
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + ;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = "客户签名";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + ;
yPos = yPos + font.GetHeight(e.Graphics) - ;
font = new Font("宋体", );
str = "-----------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics);
font = new Font("宋体", );
str = "受理单位名称";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = " 操作员名称";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin + ;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("宋体", );
str = "   日期";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("黑体", );
str = "---------------------------------";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat()); xPos = leftMargin;
yPos = yPos + font.GetHeight(e.Graphics) + ;
font = new Font("华文行楷", );
str = "此凭单为购物凭证,请妥善保管!";
e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());
} /// <summary>
/// 打印票据信息
/// </summary>
/// <param name="?">打印机名称</param>
/// <param name="sho_printNum">打印数量</param>
public void print(string str_Printer, short sho_printNum)
{
try
{
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = str_Printer;
pd.PrinterSettings.Copies = sho_printNum;
pd.PrintController = new StandardPrintController();
pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
if (pd.PrinterSettings.IsValid)
{
pd.Print();
}
else
{
MessageBox.Show("打印机连接错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
}

源码源于 ==》 http://bbs.csdn.net/topics/310215237

C# winform 打印事例的更多相关文章

  1. WinForm打印

    WinForm打印要用打印控件: PageSetupDialog:打印设置对话框 PrintDialog:打印对话框 PrintDocument:要打印的对象,非常重要 PrintPreviewCon ...

  2. c# winform打印excel(使用NPOI+Spire.xls+PrintDocument直接打印excel)

    前言 c#做winform程序要求生成并打印Excel报告,为了不安装Office相应组件,我选择了NPOI来生成Excel报告,用winform的PrintDocument控件来触发打印操作,而难点 ...

  3. winForm 打印预览

    自己很少写技术博客,虽然已经干程序员两年多了,winform开发,web开发都干过,不论项目大小对于.net的相关技术也是了解的,如mvc,wcf,wpf,silverlight,socekt通讯,n ...

  4. [asp.net]c# winform打印类

    using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using ...

  5. winform 打印控件

    (1)PageSetupDialog1    打印设置窗口  (2)PrintDocument     向打印机输送的对象 事件:PrintPage   对于打印的每一页都执行一次 (3)PrintP ...

  6. Winform 打印PDF顺序混乱,获取打印队列

    工作中PDF打印顺序混乱着实让我疼痛了好久,其实决绝方法非常简单,但没有想到这个点子的时候确实让我走了很多弯路 这里文章写出来并不是为了炫耀什么,只是觉得发现些好东西就分享出来而已,同时也做个记录,方 ...

  7. C# winform打印总结 z

    http://blog.csdn.net/jing_xin/article/details/41444063 针对BEIYANG收据打印机 BTP-R580测试通过. 操作说明:http://www. ...

  8. WinForm打印之页边距

    1.启用页边距: 默认情况下PrintDocument是不理会页边距的(MS再次让人无语...),这也是为什么有人说明明设了页边距在打印预览里却没有效果的原因. 解决办法是设置PrintDocumen ...

  9. 【2017-05-03】winform打印控件、事件对象和事件数据、MDI窗体容器

    一.打印控件 第一步先把打印对象搞出来. - printDocument    打印对象(将要打印的内容放到该对象里,从该对象里取内容打印) 设置他的PrintPage事件(对于要打印的每一页触发一次 ...

随机推荐

  1. shell脚本杀进程重启

    #!/bin/bash ID=`ps -ef | grep "abc" | grep -v "$0" | grep -v "grep" | ...

  2. Reference Type Casting

    5.5.1. Reference Type Casting Given a compile-time reference type S (source) and a compile-time refe ...

  3. 132页Filter代码分析

    1.long before = System.currentTimeMillis(); long after = System.currrentTimeMillis(); 解析:这两段代码之间定义的是 ...

  4. 各种数据库maven的pom文件编写与ibernate链接配置

    各种数据库Hibernate链接配置 Derby db driver maven dependency <dependency>         <groupId>org.ap ...

  5. ASP.NET站点部署相关

    汤姆大叔的部署指南:http://www.cnblogs.com/TomXu/archive/2011/11/25/2263050.html 中文目录: 部署介绍 --(英文版连接) 部署SQL Se ...

  6. Spring多线程编程

    在Spring框架下如何保证线程安全,如何很happy顺畅地并发编程. 常见的如下面的这坨代码,在Spring中,默认是单例的,也就是说,在同一时刻只有一个SpringOrdinaryClass的单实 ...

  7. Datenstruktur und Algorithmus

    In der Informatik und Softwaretechnik ist eine Datenstruktur ein Objekt zur Speicherung und Organisa ...

  8. 实现MySQL数据库的实时备份

    实现MySQL数据库的实时备份 使用MySQL Replication 吴剑 2018-08-03 原创文章,转载必需注明出处:http://www.cnblogs.com/wu-jian 吴剑 ht ...

  9. 在ViewDidLoad中往导航栈推ViewController报错

     Unbalanced calls to begin/end appearance transitions for <YZPMainViewController: 0x7fa04b4970f0& ...

  10. 微信WeUI入门2

    引入需要的样式文件 最重要的css文件为 weui.min.css 基本的框架如下: <!DOCTYPE html> <html lang="zh-CN"> ...