Receipt has overlapping text in Print Document - c#

I am creating a print receipt in my POS project and attach picture of the output
my problem here is the overlapping of description, qty, price, amount.
How to show the qty and price and amount in the next line from this code?
e.Graphics.DrawString("Description" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, 260));
e.Graphics.DrawString("Qty" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(120, 260));
//e.Graphics.DrawString("UM" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(190, 190));
e.Graphics.DrawString("Price", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(155, 260));
e.Graphics.DrawString("Amount" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(205, 260));
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, 275));
int yPos = 300;
foreach (var i in TempVal)
{
e.Graphics.DrawString(i.Particular + " (" + i.UM + ")", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos));
e.Graphics.DrawString(i.Qty, new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(120, yPos));
//e.Graphics.DrawString(i.UM, new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(190, yPos));
e.Graphics.DrawString(i.Price +".00", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(155, yPos));
e.Graphics.DrawString(i.Total + ".00", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(205, yPos));
yPos = yPos + 20;
}
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, yPos));
e.Graphics.DrawString("Total Amount: Php " + label3.Text.Trim(), new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos+20));
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, yPos+35));
e.Graphics.DrawString("Cash Tendered: Php " + label4.Text.Trim(), new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos + 55));
e.Graphics.DrawString("Change: Php " + lblTotal.Text.Trim(), new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos + 75));
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, yPos+95));

This will “show the qty and price and amount in the next line” as you asked:
using (var f = new Font("trebuchet ms", 10, FontStyle.Regular))
{
int yPos = 300;
foreach (var v in TempVal)
{
e.Graphics.DrawString(v.Particular + " (" + v.UM + ")", f, Brushes.Black, new Point(0, yPos));
yPos += 20;
e.Graphics.DrawString(v.Qty, f, Brushes.Black, new Point(120, yPos));
e.Graphics.DrawString(v.Price +".00", f, Brushes.Black, new Point(155, yPos));
e.Graphics.DrawString(v.Total + ".00", f, Brushes.Black, new Point(205, yPos));
yPos += 20;
}
}
Be aware this only works if TempVal is guaranteed to have so few records that they will all fit on one page. If there can be enough records to require more pages, you will have to calculate how many rows will fit on a page and split your output onto multiple pages.

Related

"Does Not Contain Definition and No Extension Method Found " But Exists in another Class

I am getting this error:
TicketingSystem' does not contain a definition for 'DVPrintDocument_PrintPage' and no extension method could be found.
I am trying to organize my code by putting it in separate classes. I made a new class called Printing.cs which has this code:
public void DVPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap r3tsLogo = Properties.Resources.rt3slogo;
Image image1 = r3tsLogo; //image 1 is r3tsLogo
e.Graphics.DrawImage(image1, 350, 0, image1.Width, image1.Height);
// e.Graphics.DrawString("Employee Name:" + employee.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 200)); //Put to bottom of paper
e.Graphics.DrawString("Address:", new Font("Impact", 12, FontStyle.Regular), Brushes.Black, new Point(300, 90));//change the new point to put text on different part of paper.
e.Graphics.DrawString("North Building", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(370, 94)); //This line of code connects to Code line 151
e.Graphics.DrawString("Email:", new Font("Impact", 12, FontStyle.Regular), Brushes.Black, new Point(300, 120));//change the new point to put text on different part of paper.
e.Graphics.DrawString("email#email.com", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(350, 124)); //This line of code connects to Code line 154
e.Graphics.DrawString("Date: " + DateTime.Now, new Font("Arial", 13, FontStyle.Regular), Brushes.Black, new Point(300, 150));
e.Graphics.DrawString(ticketingSystem.dashes.Text, new Font("Arial", 12), Brushes.Black, new Point(0, 160));
e.Graphics.DrawString("CUSTOMER INFORMATION:", new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(275, 180));
e.Graphics.DrawString("Customer Name:" + ticketingSystem.nameTxtB.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 200));
e.Graphics.DrawString("Email:" + ticketingSystem.emailTxtBox.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 230));
e.Graphics.DrawString("Cell Number:" + ticketingSystem.cellNumberTxtB.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 260));
if(ticketingSystem.studentRadioB.Checked == true)
{
e.Graphics.DrawString("Position:" + ticketingSystem.studentRadioB.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 290));
}
else if (ticketingSystem.teacherRadioB.Checked == true)
{
e.Graphics.DrawString("Position:" + ticketingSystem.teacherRadioB.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 290));
}
e.Graphics.DrawString(ticketingSystem.dashes.Text, new Font("Arial", 12), Brushes.Black, new Point(0, 350));
//--------------------------------------Device Information -------------------------------------------------------------------------------------
int y = 493;
e.Graphics.DrawString("DEVICE INFORMATION:", new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(286, 373));
e.Graphics.DrawString("Device Type:" + ticketingSystem.devices.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 403));
if (ticketingSystem.devices.Visible == true & ticketingSystem.devices.Text == "Console")
{
e.Graphics.DrawString("Type of Console:" + ticketingSystem.consoleTextBox.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 433));
}
if (ticketingSystem.comboBox3.Visible == true) //iphone selection box is visible then show selected model on print document
{
e.Graphics.DrawString("Type of Phone:" + ticketingSystem.comboBox3.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 433));
}
e.Graphics.DrawString("Service Type:" + ticketingSystem.serviceDesc.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(50, 463));
using (var arial15 = new Font("Arial", 15, FontStyle.Regular))
{
y += DrawWrapped("Price: $" + Convert.ToInt32(cPrice), arial15, new Point(50, 493), e.PageBounds.Size, e.Graphics);
}
using (var arial15 = new Font("Arial", 15, FontStyle.Regular))
{
y += DrawWrapped("Description:" + ticketingSystem.description4Repair.Text, arial15, new Point(50, y), e.PageBounds.Size, e.Graphics);
}
}
Now when I comment everything out in my Main.cs I get the same error:
TicketingSystem' does not contain a definition for 'DVPrintDocument_PrintPage' and no extension method could be found.
All I want to do is tell my designer.cs to look for the code in Printing.cs.

How to show multiple pages in PrintPreview control in c#

In my Windows application, I print multiple items in my PrintPriview control but when the items are more than 25, it doesn't go the next page to print the rest of the items. I know that we need to use e.Hasmorepages = true but I can't figure out how to use it correctly. Please help.
Screen shot -
Click here to see screen shot
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap bmp = Properties.Resources.logo2;
Image image = bmp;
e.Graphics.DrawImage(image, 0, 0, image.Width, image.Height);
e.Graphics.DrawString("Date: " + DateTime.Now.ToShortDateString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, 160));
e.Graphics.DrawString("Client Name: " + ClientNameTextBox.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, 190));
e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, 235));
e.Graphics.DrawString("Item Name", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(30, 255));
e.Graphics.DrawString("Quantity", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(380, 255));
e.Graphics.DrawString("Unit Price (£)", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(510, 255));
e.Graphics.DrawString("Total Price (£)", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(660, 255));
e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, 270));
int yPos = 295;
foreach (var i in shoppingCart)
{
e.Graphics.DrawString(i.ItemName, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(30, yPos));
e.Graphics.DrawString(i.Quantity.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(400, yPos));
e.Graphics.DrawString(i.UnitPrice.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(550, yPos));
e.Graphics.DrawString(i.TotalPrice.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(700, yPos));
yPos += 30;
}
e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, yPos));
e.Graphics.DrawString("Total Amount: £" + TotalAmountTextBox.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(550, yPos + 30));
e.Graphics.DrawString("Sales Tax (16%): £" + SalesTaxTextBox.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(550, yPos + 60));
e.Graphics.DrawString("Total To Pay: £" + TotalToPayTextBox.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(550, yPos + 90));
e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, yPos + 120));
}
Thanks in advance.
Regards,
Yes, you need to
a) watch the y value
b) set HasMorePages to true when it is over a maximum page height value
c) leave the printpage event.
It'll be called again if needed, ie when you either print or preview the next page..
You also need to keep track of the cart items you have printed in a class level variable; replace the foreach by a for loop storing/using that item number! Break out of the loop and later also return from the event when y is larger than the maximum that will fit on your page!
Also design for repeating the headers, but you got that right I think! Finally another class level variable should keep track of the page numbers!

printing on a document c# .net

i am trying to print a invoice from application for my dads business, i am using the following code to print the invoice.
My attempt is below:
{
int y = 470;
while (i < dataGridView1.RowCount)
{
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["ProductName"].Value.ToString(), DefaultFont, Brushes.Black, new Point(35, y));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["Desc"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(250, y));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["Quantity"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(600, y));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["UnitPrice"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(650, y));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["Tax"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(700, y));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["Total"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(650, y));
y = y + 20;
if (y >= pageHeight)
{
e.HasMorePages = true;
y = 0;
i++;
return;
}
else
{
e.HasMorePages = false;
}
i++;
}
}
i here is a global variable
private int i = 0;
when i click on preview button i get the output as expected but when i print it on paper only the content in the while loop is not printed. i tried using a local variable instead j of global variable as shown below and it worked.
for (int j=0; j < dataGridView1.RowCount; j++)
{
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["ProductName"].Value.ToString(), DefaultFont, Brushes.Black, new Point(35, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["Desc"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(250, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["Quantity"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(600, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["UnitPrice"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(650, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["Tax"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(700, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["Total"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(650, y));
y = y + 20;
}
but i don't know how to add new pages if the item to be included exceeds the page height. please some help.
after iterating through the code step by step i found that the code tp print the preview is run again while printing the form. so i just had to initialize the i value to 0 so that it starts printing from the beginning.
here is the code which solved it
int j;
for (j=i; j < dataGridView1.RowCount && y<e.MarginBounds.Bottom; j++)
{
e.Graphics.DrawString(e.MarginBounds.Bottom.ToString(), DefaultFont, Brushes.Black, new Point(100, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["ProductName"].Value.ToString(), DefaultFont, Brushes.Black, new Point(35, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["Desc"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(220, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["Quantity"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(770, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["UnitPrice"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(620, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["Tax"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(670, y));
e.Graphics.DrawString(dataGridView1.Rows[j].Cells["Total"].Value.ToString(), new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(720, y));
y = y + 20;
}
if (j < dataGridView1.RowCount)
{
e.HasMorePages = true;
i=j;
}
else
{
e.HasMorePages = false;
i = 0;
}

C# printing issue - printing datagridview data - 2,3,4 times the printing slowing down --Windows Form

I fill up a datagridview and after that I print out the list from there some extra fix string fields. The first two printing finishing fast but after that 3-4 is slowing down very much(sometimes it freezing).
I think some buffer or something fills up and i have to empty it but how? If I tried to print via pdf printer the first file size is normal ~200KB second is 1MB and the third is 4-6MB the fourth is so big it is freezing.
It is only one page maximum two page long list. Can someone help me to find the problem and offer a solution or more?
private void button1_Click(object sender, EventArgs e)
{
printDocument1.Print();
}
Print button
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap bmp = Properties.Resources.ugro;
Image newImage = bmp;
e.Graphics.DrawImage(newImage, 700, 20, 100, 100);
Bitmap bmp1 = Properties.Resources.line_1;
Image newImage1 = bmp1;
e.Graphics.DrawImage(newImage1, 20, 80, 700, 1);
e.Graphics.DrawString("Text", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(280, 20));
e.Graphics.DrawString(lbl_datum.Text, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, new Point(20, 20));
// e.Graphics.DrawString("Text:", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(20, 100));
//e.Graphics.DrawString(txt_BID.Text, new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(160, 80));
//e.Graphics.DrawString(txt_ID.Text, new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(160, 100));
DataGridViewCell cell = null;
foreach (DataGridViewCell selectedCell in dataGridView1.SelectedCells)
{
cell = selectedCell;
break;
}
if (cell != null)
{
DataGridViewRow row = cell.OwningRow;
}
e.Graphics.DrawString("Name", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(40, 60));
e.Graphics.DrawString("Height(cm)", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(150, 60));
e.Graphics.DrawString("Weight(kg)", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(280, 60));
e.Graphics.DrawString("Text(cm)", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(410, 60));
int height = 0;
//int width = 0;
//e.Graphics.FillRectangle(Brushes.DarkGray,new Rectangle(100,100,dataGridView1.Columns[0].Width,dataGridView1.Rows[0].Height));
// e.Graphics.DrawString(dataGridView1.Columns[0].HeaderText.ToString(), new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Rectangle(420, 80, dataGridView1.Columns[0].Width,dataGridView1.Rows[1].Height));
height = 80;
while (i < dataGridView1.Rows.Count)
{
if (height > e.MarginBounds.Height)
{
e.HasMorePages = true;
return;
}
height += 20;
//e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(20, height, dataGridView1.Columns[0].Width, 20));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(20, height, dataGridView1.Columns[0].Width+50, 40));
string sign = String.Format("_____________");
e.Graphics.DrawString(sign, dataGridView1.Font, Brushes.Black, new Rectangle(150, height, dataGridView1.Columns[0].Width + 100, 40));
e.Graphics.DrawString(sign, dataGridView1.Font, Brushes.Black, new Rectangle(280, height, dataGridView1.Columns[0].Width + 100, 40));
e.Graphics.DrawString(sign, dataGridView1.Font, Brushes.Black, new Rectangle(410, height, dataGridView1.Columns[0].Width + 100, 40));
i++;
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
}
i = 0;
}
Which variable is causing my problem?

System.Drawing & e.HasMorePages problems

I have several days trying to solve this big problem I have in C #:
I am trying to Print 21 Articles (Bill) Ticket Format, but the paper roll has a limit and occupied several pages divided print but I can not make it do the jump from page to print the article # 17 and continue to another page with the # 18, please help..
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
I think that you are not doing it right. It should go something like this:
private void MyPrintDocument_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
bool more = DrawItems(e.Graphics);
if (more == true)
e.HasMorePages = true;
}
So, after PrintDocument Print event, you call your method to draw items, and it tracks last painted item in variable outside of the method, so when it is called again to know where to start from. And when it comes to item that should go to next page, it returns true.

Categories

Resources