這是回答真的很快到來,我已經在升級問題絆倒了。
我已經改變了我的程序來從數據庫中填充一些DataSet。
我打電話Print()
上printDocument
,一切正常,它只是不希望我的註冊e.HasMorePages = true;
這裏是代碼:
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;
}
}
}
所以,當我試圖打印文檔用單頁面,一切正常,但如果我嘗試打印多頁文檔,只打印第一頁(Header,DocumentInfo,SupplierInfo,ProductLines(80條左右的38行),Footer),然後再沒有更多頁面正在打印成PDF文件..)
我在做什麼錯?
PrintProductLines
中的e參數有問題嗎?我怎樣才能告訴功能PrintProductLines
,我想從原來的功能觸發HasMorePages
?我知道我可以通過引用傳遞,但裁判關鍵字不會在我的情況下工作:S
編輯:
更改static void printDocument_PrintProductLines(ref PrintPageEventArgs e)
和printDocument_PrintProductLines(ref e);
拋出一個錯誤:
Error 2 Argument 1 must be passed with the 'ref' keyword
Error 1 The best overloaded method match for 'GZIG.globalClass.printDocument_PrintPostavke(ref System.Drawing.Printing.PrintPageEventArgs)' has some invalid arguments
您必須在PrintPage事件處理程序中將e.HasMorePages設置爲true才能獲取多個頁面。 – 2012-02-19 16:24:24
我已將整個PrintArticleLines(e)過程移回到PrintPage函數中,並且仍然不起作用。我現在正在設置HasMorePages,它仍然不起作用:( – SubjectX 2012-02-19 19:33:46