打印问题 请问大虾们如何在Winform程序中实现没有预览的打印 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我是打印报表,用了reportViewer控件,怎么能不预览 PrintDocument存在一个问题,就是如何把报表放到document中打印 using System;using System.Collections.Generic;using System.Text;using System.Drawing.Imaging;using System.IO;using System.Drawing.Printing;using Microsoft.Reporting.WinForms;namespace DLAFMS.RVP { public class ReportPrintImpl { private List<Stream> m_streams; private int m_currentPageIndex; public int CurrentPageIndex { get { return m_currentPageIndex; } set { m_currentPageIndex = value; } } private PrintDocument pDocument; public PrintDocument PDocument { get { return pDocument; } set { pDocument = value; } } public ReportPrintImpl() { pDocument = new PrintDocument(); pDocument.PrintPage += new PrintPageEventHandler(pDocument_PrintPage); } /// <summary> /// 呈现报表 /// </summary> /// <param name="report">报表</param> public void Export(LocalReport report) { StringBuilder deviceInfo = new StringBuilder(); deviceInfo.Append("<DeviceInfo>") .Append(" <OutputFormat>EMF</OutputFormat>") .Append(" <PageWidth>8.5in</PageWidth>") .Append(" <PageHeight>11in</PageHeight>") .Append(" <MarginTop>0.1in</MarginTop>") .Append(" <MarginLeft>0.2in</MarginLeft>") .Append(" <MarginRight>0.1in</MarginRight>") .Append(" <MarginBottom>0.1in</MarginBottom>") .Append("</DeviceInfo>"); Warning[] warnings; m_streams = new List<Stream>(); report.Render("Image", deviceInfo.ToString(), CreateStream, out warnings); foreach (Stream stream in m_streams) { stream.Position = 0; } } 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 pDocument_PrintPage(object sender, PrintPageEventArgs e) { Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]); e.Graphics.DrawImage(pageImage, 0, 0); m_currentPageIndex++; e.HasMorePages = (m_currentPageIndex < m_streams.Count); } }}调用如下所示:ReportForm frmReport = new ReportForm();//报表窗体ReportInitImpl report = new ReportInitImpl();//填充报表数据的类,换成你自己的ReportPrintImpl reportPrint = new ReportPrintImpl();//直接打印的类report.InitReportData(frmReport.rv_License, license);//将数据填充到报表中,换成你自己的frmReport.Show();frmReport.rv_License.SetDisplayMode(DisplayMode.PrintLayout);frmReport.rv_License.ZoomMode = ZoomMode.Percent;reportPrint.CurrentPageIndex = 0;reportPrint.Export(frmReport.rv_License.LocalReport);reportPrint.PDocument.Print();frmReport.Close(); class ReportPrintImpl 就是直接打印的处理类。reportViewer控件难道没有放在窗体中吗? public void Print() { PrintDocument pd = new PrintDocument(); //默认纸张设计属性 pd.DefaultPageSettings.PaperSize = new PaperSize("StuffBusicInfo", 1024, 768); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); //使用预览对话框模拟打印效果 PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = pd; ppd.ShowDialog(); } try.........catch 问题 求 HyperLink 绑定数据科学方法 c#调用bat文件问题 IE 装载.net UserControl c#中如何知道一个过程执行完毕? 记事本程序中如何控制光标? Exception from HRESULT:0X80010105(RPC_E_SERVERFAULT). 用C#开发这个WEB应用程序,收多少开发费为谊? 怎样用右键强出菜单? 自定义控件放置splitContainer问题(没分了) 数组元素组合问题 基础问题
using System.Collections.Generic;
using System.Text;
using System.Drawing.Imaging;
using System.IO;
using System.Drawing.Printing;
using Microsoft.Reporting.WinForms;namespace DLAFMS.RVP {
public class ReportPrintImpl {
private List<Stream> m_streams;
private int m_currentPageIndex;
public int CurrentPageIndex {
get { return m_currentPageIndex; }
set { m_currentPageIndex = value; }
}
private PrintDocument pDocument;
public PrintDocument PDocument {
get { return pDocument; }
set { pDocument = value; }
} public ReportPrintImpl() {
pDocument = new PrintDocument();
pDocument.PrintPage += new PrintPageEventHandler(pDocument_PrintPage);
} /// <summary>
/// 呈现报表
/// </summary>
/// <param name="report">报表</param>
public void Export(LocalReport report) {
StringBuilder deviceInfo = new StringBuilder();
deviceInfo.Append("<DeviceInfo>")
.Append(" <OutputFormat>EMF</OutputFormat>")
.Append(" <PageWidth>8.5in</PageWidth>")
.Append(" <PageHeight>11in</PageHeight>")
.Append(" <MarginTop>0.1in</MarginTop>")
.Append(" <MarginLeft>0.2in</MarginLeft>")
.Append(" <MarginRight>0.1in</MarginRight>")
.Append(" <MarginBottom>0.1in</MarginBottom>")
.Append("</DeviceInfo>"); Warning[] warnings;
m_streams = new List<Stream>();
report.Render("Image", deviceInfo.ToString(), CreateStream, out warnings); foreach (Stream stream in m_streams) {
stream.Position = 0;
}
} 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 pDocument_PrintPage(object sender, PrintPageEventArgs e) {
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
e.Graphics.DrawImage(pageImage, 0, 0);
m_currentPageIndex++;
e.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
}
}
调用如下所示:
ReportForm frmReport = new ReportForm();//报表窗体
ReportInitImpl report = new ReportInitImpl();//填充报表数据的类,换成你自己的
ReportPrintImpl reportPrint = new ReportPrintImpl();//直接打印的类
report.InitReportData(frmReport.rv_License, license);//将数据填充到报表中,换成你自己的
frmReport.Show();
frmReport.rv_License.SetDisplayMode(DisplayMode.PrintLayout);
frmReport.rv_License.ZoomMode = ZoomMode.Percent;
reportPrint.CurrentPageIndex = 0;
reportPrint.Export(frmReport.rv_License.LocalReport);
reportPrint.PDocument.Print();
frmReport.Close();
reportViewer控件难道没有放在窗体中吗?
{
PrintDocument pd = new PrintDocument();
//默认纸张设计属性
pd.DefaultPageSettings.PaperSize = new PaperSize("StuffBusicInfo", 1024, 768);
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
//使用预览对话框模拟打印效果
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = pd;
ppd.ShowDialog();
}