- Print multiple pages in WinForms doesn't work
- public static void printDokument()
- {
- if (result == DialogResult.OK)
- {
- DbDataPostavke = checkDB("SELECT * FROM " + tipDokumenta + "_postavke WHERE ID_" + tipDokumenta + " = " + stDokumenta);
- list = DbDataPostavke.Tables[0].AsEnumerable().ToList();
- printDocument.Print();
- }
- }
- static void printDocument_PrintPage(object sender, PrintPageEventArgs e)
- {
- graphic = e.Graphics;
- e.PageSettings.PaperSize = ps;
- stranSirina = e.PageSettings.PrintableArea.Width;
- stranVisina = e.PageSettings.PrintableArea.Height;
- fontHeight = font.GetHeight();
- //this works/prints
- printDocument_PrintHeader();
- //this works/prints
- printDocument_PrintDocumentInfo();
- if (firstPage) printDocument_PrintSupplierInfo();
- //Lines that I take from DB, amount of this lines is variable //it only prints one page, then it stops printing
- printDocument_PrintProductLines(e);
- //Sum of lines
- if(zadnjaStran) printDocument_printSum();
- //prints comment on document
- if (zadnjaStran) printDocument_PrintComment();
- //footer
- printDocument_PrintFooter();
- }
- static void printDocument_PrintProductLines(PrintPageEventArgs e)
- {
- //I print some stuff here (header, etc..)
- String stranArtikliVrstica = String.Empty; // string for one line of data
- DataRow dataRow1 = null;
- DataRow dr = null;
- for(int i = 0; i < list.Count(); i++)
- {
- dr = list[i];
- dataRow1 = poglejBazo("SELECT ime, EM, opis FROM Sifrant WHERE ID = " + dr[2].ToString()).Tables[0].Rows[0];
- stranArtikliVrstica = String.Format("{0,-38} {1,10} {2,5} {3,9:C} {4,9:C}", dataRow1[0].ToString() + " - " + dataRow1[2].ToString(), dr[3].ToString(), dataRow1[1].ToString(), dr[4], Convert.ToInt16(dr[3]) * Convert.ToInt16(dr[4]));
- list.Remove(dr);
- graphic.DrawString(stranArtikliVrstica, font, brush, startX + offsetX, startY + offsetY);
- offsetY += (int)font.GetHeight();
- //if there is less then 35 "lines" remaining, we have enough space for printing some other stuff, otherwise, that stuff doesn't print..
- if (list.Count() < 35) zadnjaStran = true;
- else zadnjaStran = false;
- if (offsetY > stranVisina - 50)
- {
- prvaStran = false;
- stevecStrani++;
- offsetY = 0;
- e.HasMorePages = true;
- return;
- }
- }
- }