C# winform 打印事例
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 打印事例的更多相关文章
- WinForm打印
WinForm打印要用打印控件: PageSetupDialog:打印设置对话框 PrintDialog:打印对话框 PrintDocument:要打印的对象,非常重要 PrintPreviewCon ...
- c# winform打印excel(使用NPOI+Spire.xls+PrintDocument直接打印excel)
前言 c#做winform程序要求生成并打印Excel报告,为了不安装Office相应组件,我选择了NPOI来生成Excel报告,用winform的PrintDocument控件来触发打印操作,而难点 ...
- winForm 打印预览
自己很少写技术博客,虽然已经干程序员两年多了,winform开发,web开发都干过,不论项目大小对于.net的相关技术也是了解的,如mvc,wcf,wpf,silverlight,socekt通讯,n ...
- [asp.net]c# winform打印类
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using ...
- winform 打印控件
(1)PageSetupDialog1 打印设置窗口 (2)PrintDocument 向打印机输送的对象 事件:PrintPage 对于打印的每一页都执行一次 (3)PrintP ...
- Winform 打印PDF顺序混乱,获取打印队列
工作中PDF打印顺序混乱着实让我疼痛了好久,其实决绝方法非常简单,但没有想到这个点子的时候确实让我走了很多弯路 这里文章写出来并不是为了炫耀什么,只是觉得发现些好东西就分享出来而已,同时也做个记录,方 ...
- C# winform打印总结 z
http://blog.csdn.net/jing_xin/article/details/41444063 针对BEIYANG收据打印机 BTP-R580测试通过. 操作说明:http://www. ...
- WinForm打印之页边距
1.启用页边距: 默认情况下PrintDocument是不理会页边距的(MS再次让人无语...),这也是为什么有人说明明设了页边距在打印预览里却没有效果的原因. 解决办法是设置PrintDocumen ...
- 【2017-05-03】winform打印控件、事件对象和事件数据、MDI窗体容器
一.打印控件 第一步先把打印对象搞出来. - printDocument 打印对象(将要打印的内容放到该对象里,从该对象里取内容打印) 设置他的PrintPage事件(对于要打印的每一页触发一次 ...
随机推荐
- 通过数据库绑定的dropdownlist,如何让其第一条默认显示"--请选择--"
第一种方法 DropDownList1.Items.Insert(0,"请选择XXX"); 第二种方法 在第一个位置插入一个项就可以 DropDownList1.Items.Ins ...
- (转)调优 DB2 UDB v8.1 及其数据库的最佳实践
原文:https://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0404mcarthur/index.html 简介 性能是 ...
- Android多媒体之view,SurfaceView,GLSurfaceView
1.相关概念 不用画布,直接在窗口上进行绘图叫做无缓冲绘图. 用了一个画布,将所有内容都先画到画布上,在整体绘制到窗口上,就该叫做单缓冲绘图, 那个画布就是一个缓冲区.用了两个画布,一个进行临时的绘图 ...
- AngularJS 的常用特性(三)
6.表达式 在模板中使用表达式是为了以充分的灵活性在模板.业务逻辑和数据之间建立联系,同时又能避免让业务逻辑渗透到模板中. <div ng-controller="SomeContr ...
- 利用keepalived构建高可用MySQL-HA
关于MySQL-HA,目前有多种解决方案,比如heartbeat.drbd.mmm.共享存储,但是它们各有优缺点.heartbeat.drbd配置较为复杂,需要自己写脚本才能实现MySQL自动切换,对 ...
- Perl入门
Perl 是一门开源的脚本语言,由 Larry Wall 所创造,该语言以实用,快速开发为主要目标,与当前流行的面向对象结构化编程有些格格不入,但这并不妨碍 Perl 被广泛流传和使用,世界范围内围绕 ...
- mysql-5.6.31安装(单实例 Linux)
安装版本:mysql-5.6.31 安装环境:Linux RHEL6.5.x86 安装要求:单实例,端口为默认:3306 (1) 要求安装Mysql数据库版本号及包名为:my ...
- C#泛型设计的一个小陷阱.
距离上次发表博客已经有几年了. 对于没能坚持更新博客,实在是感觉到甚是惭愧. 闲言少叙, 直接切入主题. 背景 最近一直在对于公司一个网络通信服务程序使用.net core 进行重构.重构的目的有两个 ...
- Android四大组件--服务(Service)
1. startService和bindService的区别 1. startService: 生命周期: onCreate---onStartCommand---onDestory 与服务的通讯: ...
- DateTime compare
DateTime t1 = new DateTime(100); DateTime t2 = new DateTime(20); if (DateTime.Compare(t1, t2) > 0 ...