This period of time to do the report, with the RDLC customer always response, print to press several times to print, their own test, found that there is a problem, it seems that the printing is in the pop-up print window, the first click is the current form activated, the second click will really trigger the printing event, query: http:/ /msdn.microsoft.com/zh-cn/library/ms252091 (v=vs.100). aspx
Modified the inside several places, as follows:
using system;using system.io;using system.data;using system.text;using system.drawing.imaging;using system.drawing.printing;using system.collections.generic;using system.windows.forms;using microsoft.reporting.winforms;using system.drawing;namespace ymparking.parkingmg{ public class print { int m_currentPageIndex; IList<Stream> m_streams; // Summary: // provides a flow for the ReportViewer control to render. // // return Results The: // reportviewer control can write data to the Stream objects. &Nbsp; private stream createstream (string name, string fileNameExtension, Encoding encoding, string mimetype, bool willseek) { stream stream = new memorystream (); m_streams. ADD (Stream); return stream; } /// < summary> /// Export the report file in a specified format /// </summary> /// < param Name= "Report" > Reporting file </param> private void Export (Localreport report) { 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; m_streams = New list<stream> (); report. Render ("Image", deviceinfo, createstream, out warnings); foreach (stream stream in m_streams) stream. position = 0; } // Handler for PrintPageEvents Private void printpage (Object sender, printpageeventargs ev) { metafile pageImage = new metafile (M_streams[m_currentpageindex]); rectangle adjustedrect = new rectangle ( ev. pagebounds.left - (int) EV. pagesettings.hardmarginx, ev. pagebounds.top - (int) ev. pagesettings.hardmarginy, ev. pagebounds.width, ev. Pagebounds.height); ev. Graphics.FillRectangle (Brushes.white, adjustedrect); ev. Graphics.DrawImage (Pageimage, adjustedrect); m_currentpageindex++; ev. hasmorepages = (M_currentpageindex < m_streams. Count); } /// <summary> /// Printing /// </summary> /// <param name= "Isshowprint" > whether to eject the print window </param> private void printfiel (Bool isshowprint) { if (m_streams == null | | m_streams. count == 0) throw new exception ("Specified print file error"); PrintDocument document; if (Isshowprint) { PrintDialog pd = New printdialog (); if (PD. ShowDialog () == dialogresult.ok) { document = new printdocument (); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;PD. document = document; } else { return; } } else { Document = new printdocument (); } if (!document. Printersettings.isvalid) { &nBsp; throw new exception ("Error connecting printer"); } else { document. Printpage += new printpageeventhandler (PrintPage); m_currentPageIndex = 0; document. Print (); } } public void run (LocalReport report, bool isshowprint) { export (report); printfiel (isshowprint); } public void dispose () { if (m_streams != null) { foreach (Stream stream in m_streams) stream. Close (); m_streams = null; } } }}
Write this common class, rewrite the ReportViewer Print event,
private void Reportviewer1_print (object sender, CancelEventArgs e)
{
E.cancel = true;
Print pt = new print ();
Pt. Run (Reportviewer1.localreport, true);
}
By this point, the problem has been solved.
This article is from the "Warm Dream scar" blog, please be sure to keep this source http://317057112.blog.51cto.com/1361376/1604758
Resolve the RDLC report to bring the printing, pop-up printing interface, often must press two times to print before execution