0
我有幾天試圖解決我在C#中遇到的這個大問題: 我試圖打印21條(Bill)票據格式,但紙卷有限制和佔用幾個頁面分割打印,但我不能讓它做從頁面跳轉打印文章#17,並繼續與#18的另一頁,請幫助..System.Drawing&e.HasMorePages問題
private void DrawItems(System.Drawing.Printing.PrintPageEventArgs e)
{
int linesprinted = 0;
int linesperpage = 17;
int numberitems = items.Count; //21
//numberitems/linespage = 1.23 = 2 Pages True :)
if (linesprinted <= linesperpage)
{
linesprinted++;
e.HasMorePages = false;
}
else {
linesprinted=0;
e.HasMorePages = true;
}
//print items
OrderItem ordIt = new OrderItem('?');
gfx.DrawString("C/P DESCRIPCION TOTAL", new Font(fontName, fontSize, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
DrawEspacio();
gfx.DrawString(DottedLine(), new Font(fontName, 9, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
count++;
foreach (string item in items)
{
String ItemCantidad = ordIt.GetItemCantidad(item);
String ItemPrice = ordIt.GetItemPrice(item);
Int16 not_equal = 0;
gfx.DrawString(ItemCantidad + " x", new Font(fontName, fontSize, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
line = ordIt.GetItemUnitPrice(item);
line = AlignRightText(line.Length) + line;
gfx.DrawString(" " + line, printFont, myBrush, leftMargin, YPosition(), new StringFormat());
string name = ordIt.GetItemName(item);
leftMargin = 0;
if (name.Length > maxCharDescription)
{
int currentChar = 0;
int itemLenght = name.Length;
while (itemLenght > maxCharDescription)
{
line = ordIt.GetItemName(item);
gfx.DrawString(" " + line.Substring(currentChar, maxCharDescription), new Font(fontName, fontSize, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
count++;
not_equal++;
if (not_equal == 1)
{
gfx.DrawString(ItemPrice, new Font(fontName, fontSize, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
}
currentChar += maxCharDescription;
itemLenght -= maxCharDescription;
}
line = ordIt.GetItemName(item);
gfx.DrawString(" " + line.Substring(currentChar, line.Length - currentChar), new Font(fontName, fontSize, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
count++;
gfx.DrawString("-----", new Font(fontName, fontSize, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
count++;
}
else
{
gfx.DrawString(" " + ordIt.GetItemName(item), new Font(fontName, fontSize, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
count++;
gfx.DrawString(ItemPrice, new Font(fontName, fontSize, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
count++;
gfx.DrawString("-----", new Font(fontName, fontSize, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
count++;
}
} //end foreach
leftMargin = 0;
gfx.DrawString(DottedLine(), new Font(fontName, 9, FontStyle.Regular), myBrush, leftMargin, YPosition(), new StringFormat());
DrawEspacio();
} //end function