listview - How to force print dialogue to print a given page range in c# -
i want print listview items. code have written follows:
private void printdata_click(object sender, eventargs e) { printdialog1.showhelp = true; printdialog1.document = pdoclistview; dialogresult result = printdialog1.showdialog(); printdialog1.allowsomepages = true; printdialog1.showhelp = true; printdialog1.allowselection = true; if (result == dialogresult.ok) { printdialog1.printersettings.frompage = 1; printdialog1.printersettings.topage = 1; pdoclistview.printersettings.frompage = 1; pdoclistview.printersettings.topage = 1; pdoclistview.print(); } } private void document_printpage(object sender, system.drawing.printing.printpageeventargs e) { e.hasmorepages = !lsvpersonnelwisebook.printmultilinedata( e.marginbounds.location, e.marginbounds.bottom, e.graphics, brushes.blue, brushes.black, pens.blue); } public static bool printmultilinedata(this listview lvw, point location, float max_y, graphics gr, brush header_brush, brush data_brush, pen grid_pen) { const int x_margin = 2; const int y_margin = 3; float x = location.x; float y = location.y; float screen_res_x; using (graphics screen_gr = lvw.creategraphics()) { screen_res_x = screen_gr.dpix; } float screen_to_printer = 100 / (screen_res_x + 45); float[] col_wids = new float[lvw.columns.count]; (int = 0; < lvw.columns.count; i++) col_wids[i] = (lvw.columns[i].width + 2 * x_margin) * screen_to_printer; int num_columns = lvw.columns.count; using (stringformat string_format = new stringformat()) { // draw column headers. string_format.alignment = stringalignment.center; string_format.linealignment = stringalignment.center; var header_query = columnheader column in lvw.columns select column.text; drawmultilineitems(header_query.toarray(), gr, lvw.font, header_brush, grid_pen, max_y, x_margin, y_margin, x, ref y, col_wids, num_columns, string_format); //draw data. string_format.alignment = stringalignment.near; while (nextlistviewrow < lvw.items.count) { listviewitem item = lvw.items[nextlistviewrow]; var subitems_query = listviewitem.listviewsubitem subitem in item.subitems select subitem.text; if (!drawmultilineitems(subitems_query.toarray(), gr, lvw.font, data_brush, grid_pen, max_y, x_margin, y_margin, x, ref y, col_wids, num_columns, string_format)) return false; nextlistviewrow++; } } nextlistviewrow = 0; return true; }
when click on print button prints 2 pages. need print page range give input in selected page range. there way?
Comments
Post a Comment