润宇软件
首 页 企业简介 项目案例 软件定制 行业软件 解决方案 企业动态 服务专区 客服中心
业务介绍:西安软件公司、软件开发、软件定制、软件外包
软件 方案 文章
  润宇软件 >> 新闻资讯  >> 解决方案

软件公司winform软件实现打印功能

发布时间:2015/9/4  浏览次数:18次  字体【    】

操作步骤:
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
);
}
}
}
  关闭本页
西部IT网合作伙伴 合作伙伴
陕西省 | 榆林 | 延安 | 铜川 | 渭南 | 商洛 | 宝鸡 | 汉中 | 安康 | 咸阳
网站首页 | 关于我们 | 售后服务 | 项目合同 | 查看留言 | 在线留言 | 客服中心
© 版权所有:西安润宇软件科技有限公司 
公司地址:西安市丝路国际创意梦工厂4号楼 联系电话:029-87878512 手机:13468700578 联系人:李先生
Copyright ® 2009-2020 RunYusoft.com Inc. All Rights Reserved 
技术支持:西安润宇软件科技有限公司  陕ICP备11000720号-3