C#调用打印机打印图片
2014-03-11 16:43
555 查看
可以使用打印控件打印,在Toolbox中有PrintDocument,并且设置相应的事件监听。
双击PringDocument进行监听方法的实现
设置一个button来触发打印,在这个button的click事件中编写代码
如何打印一个Reporting Service报表?
这里没有用到控件,所需要的类都是通过new的方式获得的。其实,控件的方式就是让用户更加直接简单的使用工具类,与new的方式没有本质的区别。如果想更加可控的使用这个类并且很熟悉的时候,可以绕过拖动控件直接new.
双击PringDocument进行监听方法的实现
private void PicturePrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { try { if (pictureBox.Image != null) { e.Graphics.DrawImage((pictureBox.Image, e.Graphics.VisibleClipBounds); e.HasMorePages = false; } } catch (Exception exception) { Log... } }
设置一个button来触发打印,在这个button的click事件中编写代码
private void button_Click(object sender, System.EventArgs e) { PrintDialog printDialog = new PrintDialog(); printDialog.Document = picturePrintDocument; if (printDialog.ShowDialog(this) == DialogResult.OK) //到这里会出现选择打印项的窗口 { sectionPicturePrintDocument.Print(); //到这里会出现给文件命名的窗口,点击确定后进行打印并完成打印 } }
如何打印一个Reporting Service报表?
LocalReport report = new LocalReport(); //...对于report的各种设置,在这里组成一个完整的报表,接下来就是打印报表 private IList<Stream> m_streams; private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek) { Stream stream = new FileStream(@"" + name + "." + fileNameExtension, FileMode.Create); m_streams.Add(stream); return stream; } private void P1() { m_streams = new List<Stream>(); string deviceInfo = "<DeviceInfo>" + " <OutputFormat>EMF</OutputFormat>" + " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>" + " <MarginTop>0.25in</MarginTop>" + " <MarginLeft>0.25in</MarginLeft>" + " <MarginRight>0.25in</MarginRight>" + " <MarginBottom>0.25in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; report.Render("Image", deviceInfo, CreateStream, out warnings); foreach (Stream stream in m_streams) stream.Position = 0; if (m_streams == null || m_streams.Count == 0) return; PrintDocument printDoc = new PrintDocument(); PrintDialog pdi = new PrintDialog(); pdi.Document = printDoc; printDoc.PrintPage += new PrintPageEventHandler(PrintPage); if (pdi.ShowDialog() == DialogResult.OK) { printDoc.Print(); } } private void PrintPage(object sender, PrintPageEventArgs ev) { Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]); ev.Graphics.DrawImage(pageImage, ev.PageBounds); m_currentPageIndex++; ev.HasMorePages = (m_currentPageIndex < m_streams.Count); }
这里没有用到控件,所需要的类都是通过new的方式获得的。其实,控件的方式就是让用户更加直接简单的使用工具类,与new的方式没有本质的区别。如果想更加可控的使用这个类并且很熟悉的时候,可以绕过拖动控件直接new.
相关文章推荐
- C#调用打印机,打印图片
- C#调用打印机,打印图片
- C# 调用打印机打印图片
- java调用打印机打印自定义的图片
- C#调用斑马打印机打印条码标签(支持COM、LPT、USB、TCP连接方式和ZPL、EPL、CPCL指令)【转】
- C#调用斑马打印机打印条码标签(支持COM/LPT/USB/ZPL/EPL/Bitmap)
- C#调用斑马打印机打印条码标签(支持COM/LPT/USB/ZPL/EPL/Bitmap)
- C#调用斑马打印机打印条码标签(支持COM、LPT、USB、TCP连接方式和ZPL、EPL、CPCL指令)
- C#在调用CodeSoft打印时修改了打印机的打印参数问题
- c#调用打印机打印水晶报表
- C# 热敏打印机 小票打印机 打印图片
- C#调用斑马打印机打印条码标签(支持COM、LPT、USB、TCP连接方式和ZPL、EPL、CPCL指令)
- Java调用打印机打印指定路径图片
- C#调用TSC条码打印机打印二维码
- C# 热敏打印机 小票打印机 打印图片
- C#调用斑马打印机打印条码标签(支持COM、LPT、USB、TCP连接方式和ZPL、EPL、CPCL指令)
- Java 调用打印机打印图片
- C#调用TSC条码打印机打印条码
- C#生成条码图片,并用条码打印机打印
- C#调用斑马打印机打印条码标签(支持COM、LPT、USB、TCP连接方式和ZPL、EPL、CPCL指令)