i´m trying print datagridview , printer prints white page. know datagridview not empty because appear on form. tried doing printpreviewdialog shows white page. code , dont know wrong.
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.drawing.printing; namespace prueba { public partial class form4 : form { public form4() { initializecomponent(); } private void imprimirbtn_click(object sender, eventargs e) { printdocument1.print(); } private void printdocument1_printpage(object sender, system.drawing.printing.printpageeventargs e) { font printfont = new font("arial", 10); float topmargin = e.marginbounds.top; float ypos = 0; float linesperpage = 0; int count = 0; string texto = ""; int = -1; datagridviewrow row; linesperpage = e.marginbounds.height / printfont.getheight(e.graphics); while (count < linesperpage && < this.datagridview1.rows.count) { row = datagridview1.rows[i]; texto = ""; foreach (datagridviewcell celda in row.cells) { texto += "\t" + celda.value.tostring(); } ypos = topmargin + (count * printfont.getheight(e.graphics)); e.graphics.drawstring(texto, printfont, brushes.black, 10, ypos); count++; i++; if (i < this.datagridview1.rows.count) e.hasmorepages = true; else { = 0; } } } }
you forgot add eventhandler printing process.
private void imprimirbtn_click(object sender, eventargs e) { printdocument1.printpage += new printpageeventhandler(printdocument1_printpage); printdocument1.print(); }
Comments
Post a Comment