C#调用打印机,打印图片
2013-11-07 11:11
351 查看
PrintPreviewDialog是打印预览对话框,需要传一个 printDocument给它才可以显示该对话框
PrintDocument是具体要打印的内容,可以是图片,也可以是加载文档,文字。
代码如下:
PrintDocument是具体要打印的内容,可以是图片,也可以是加载文档,文字。
代码如下:
//打印 private void button5_Click(object sender, EventArgs e) { //获取或设置一个值,该值指示是否发送到文件或端口 printDocument1.PrinterSettings.PrintToFile = true; //设置打印时横向还是纵向 printDocument1.DefaultPageSettings.Landscape = true; //打印预览 // PrintPreviewDialog ppd = new PrintPreviewDialog(); if (bmp == null) { return; } //设置边距 Margins margin = new Margins(20, 20, 20, 20); printDocument1.DefaultPageSettings.Margins = margin; ////纸张设置默认 //PaperSize pageSize = new PaperSize("First custom size", 800, 600); //pd.DefaultPageSettings.PaperSize = pageSize; //打印事件设置 printDocument1.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); //ppd.Document = printDocument1; // ppd.ShowDialog(); try { printDocument1.Print(); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error); printDocument1.PrintController.OnEndPrint(printDocument1, new PrintEventArgs()); } } //打印事件处理 private void pd_PrintPage(object sender, PrintPageEventArgs e) { int x = e.MarginBounds.X; int y = e.MarginBounds.Y; int width = bmp.Width; int height = bmp.Height; Rectangle destRect = new Rectangle(x, y, width, height); e.Graphics.DrawImage(bmp, destRect, 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel); }
相关文章推荐
- C# 获取COM控件注册状态,注册以及反注册COM控件
- C#实现Bitmap旋转
- C#打开xml,并绑定TreeView
- C#打开文件,文件夹
- c# is as 和强制类型转换
- C# 路由器互动操作
- .NET(c#)new关键字的三种用法
- c#中的readonly和const
- C# 调用父窗体的方法
- C#中base的用法
- C#操控 条形码扫描枪
- Print2flash在.NET(C#)64位中的使用,即文档在线预览
- C#读取Excel遇到无法读取的解决方法
- C#数组基础
- C# WinForm 如何设置窗体背景为渐变色
- C# objiect 转int类型
- C# WinForm 模态对话框与非模态对话框的区别
- c#之接口
- C# 委托和Lambda表达式
- C# 同步调用、异步调用、异步回调