winform 实现打印功能
2011-12-02 22:05
260 查看
学习c# winform 打印 参照了网络上诸多资源
效果示意:
操作步骤:
1、新建winform项目及创建窗体
2、拖取 打印 相关控件
PageSetupDialog 、 PrintDialog 、 PrintDocument 、PrintPreviewDialog
3、设置上述控件的Document属性为相应的PrintDocument
4、设置按钮等控件 及 添加相应按钮事件
5、示意代码如下
代码
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
this.printDocument1.OriginAtMargins = true;//启用页边距
this.pageSetupDialog1.EnableMetric = true; //以毫米为单位
}
//打印设置
private void btnSetPrint_Click(object sender, EventArgs e)
{
this.pageSetupDialog1.ShowDialog();
}
//打印预览
private void btnPrePrint_Click(object sender, EventArgs e)
{
this.printPreviewDialog1.ShowDialog();
}
//打印
private void btnPrint_Click(object sender, EventArgs e)
{
if (this.printDialog1.ShowDialog() == DialogResult.OK)
{
this.printDocument1.Print();
}
}
//打印内容的设置
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
////打印内容 为 整个Form
//Image myFormImage;
//myFormImage = new Bitmap(this.Width, this.Height);
//Graphics g = Graphics.FromImage(myFormImage);
//g.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size);
//e.Graphics.DrawImage(myFormImage, 0, 0);
////打印内容 为 局部的 this.groupBox1
//Bitmap _NewBitmap = new Bitmap(groupBox1.Width, groupBox1.Height);
//groupBox1.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
//e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);
//打印内容 为 自定义文本内容
Font font = new Font("宋体", 12);
Brush bru = Brushes.Blue;
for (int i = 1; i <= 5; i++)
{
e.Graphics.DrawString("Hello world ", font, bru, i*20, i*20);
}
}
}
if ($ != jQuery) {
$ = jQuery.noConflict();
}
var isLogined = true;
var cb_blogId = 97235;
var cb_entryId = 2247406;
var cb_blogApp = "liehuzuo";
var cb_blogUserGuid = "ff68afc6-5cdf-e011-8ee0-842b2b196315";
var cb_entryCreatedDate = '2011/11/13 17:33:00';
标签
效果示意:
操作步骤:
1、新建winform项目及创建窗体
2、拖取 打印 相关控件
PageSetupDialog 、 PrintDialog 、 PrintDocument 、PrintPreviewDialog
3、设置上述控件的Document属性为相应的PrintDocument
4、设置按钮等控件 及 添加相应按钮事件
5、示意代码如下
代码
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
this.printDocument1.OriginAtMargins = true;//启用页边距
this.pageSetupDialog1.EnableMetric = true; //以毫米为单位
}
//打印设置
private void btnSetPrint_Click(object sender, EventArgs e)
{
this.pageSetupDialog1.ShowDialog();
}
//打印预览
private void btnPrePrint_Click(object sender, EventArgs e)
{
this.printPreviewDialog1.ShowDialog();
}
//打印
private void btnPrint_Click(object sender, EventArgs e)
{
if (this.printDialog1.ShowDialog() == DialogResult.OK)
{
this.printDocument1.Print();
}
}
//打印内容的设置
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
////打印内容 为 整个Form
//Image myFormImage;
//myFormImage = new Bitmap(this.Width, this.Height);
//Graphics g = Graphics.FromImage(myFormImage);
//g.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size);
//e.Graphics.DrawImage(myFormImage, 0, 0);
////打印内容 为 局部的 this.groupBox1
//Bitmap _NewBitmap = new Bitmap(groupBox1.Width, groupBox1.Height);
//groupBox1.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
//e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);
//打印内容 为 自定义文本内容
Font font = new Font("宋体", 12);
Brush bru = Brushes.Blue;
for (int i = 1; i <= 5; i++)
{
e.Graphics.DrawString("Hello world ", font, bru, i*20, i*20);
}
}
}
if ($ != jQuery) {
$ = jQuery.noConflict();
}
var isLogined = true;
var cb_blogId = 97235;
var cb_entryId = 2247406;
var cb_blogApp = "liehuzuo";
var cb_blogUserGuid = "ff68afc6-5cdf-e011-8ee0-842b2b196315";
var cb_entryCreatedDate = '2011/11/13 17:33:00';
标签
相关文章推荐
- winform 实现打印功能
- winform实现发票打印功能
- winform简单打印功能实现
- Winform的技巧琐碎总结----简单打印功能实现
- winform 实现打印功能
- winform 实现打印功能
- winform 实现打印功能
- winform 实现打印功能
- Winform中代码Dialog控件实现(打开,保存,改变字体,颜色,打印功能)
- javascript实现打印功能
- 用java实现打印功能
- ASP网站远程客户实现EXCEL打印功能
- C# WinForm 实现增删改查等功能(Access版) 系列之八-导出数据到Excel
- Java实现按年月打印日历功能【基于Calendar】
- 在C#中实现打印功能(C#中PrintDialog,PrintDocument的使用)
- 开源的javascript实现页面打印功能,兼容所有的浏览器(情况属实)
- 用java实现打印功能
- 基于文档/视图模式实现网页浏览以及打印功能
- 打印功能实现
- Qt实现保存、浏览、预览、打印功能的示例代码