Related
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.
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!
Working on a project that requires me to create a shipping label and store it as PNG. I've setup the layout and everything looks good when I view the PNG file, but when I go to print on the thermal/ink jet/laser printer the quality is horrible.
I've searched all over but I can't find anything that seems to address my issue. I'm not a graphics person but I'm wondering if I need to build the file in a higher resolution, but the end result needs to be a 4 by 6 shipping label. What is the best method to improve the image quality?
Below is the code that is used to generate PNG file:
Bitmap bitMapImage = new System.Drawing.Bitmap("blanklabel.png");
Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
string dttime = DateTime.Now.ToString("HHmmss");
// Create pen.
Pen blackPen0 = new Pen(Color.Gray, 1);
Pen blackPen1 = new Pen(Color.Black, 1);
Pen blackPen2 = new Pen(Color.Black, 2);
Pen blackPen3 = new Pen(Color.Black, 3);
//Top Rectangle - Draw Box
Rectangle topRect = new Rectangle(5, 5, 367, 338);
graphicImage.DrawRectangle(blackPen1, topRect);
//Top Rectangle - Horizontial Lines
graphicImage.DrawLine(blackPen1, 5, 41, 372, 41);
graphicImage.DrawLine(blackPen1, 5, 77, 372, 77);
graphicImage.DrawLine(blackPen2, 5, 129, 372, 129);
graphicImage.DrawLine(blackPen2, 5, 210, 372, 210);
graphicImage.DrawLine(blackPen0, 5, 225, 372, 225); //Draw row1 in middle
graphicImage.DrawLine(blackPen0, 5, 240, 372, 240); //Draw row2 in middle
graphicImage.DrawLine(blackPen0, 5, 255, 372, 255); //Draw row3 in middle
graphicImage.DrawLine(blackPen1, 5, 271, 372, 271);
graphicImage.DrawLine(blackPen1, 5, 322, 372, 322);
//Top Rectangle - Vertical Lines
graphicImage.DrawLine(blackPen1, 258, 41, 258, 322);
graphicImage.DrawLine(blackPen1, 103, 210, 103, 271);
graphicImage.DrawLine(blackPen1, 172, 210, 172, 271);
//graphicImage.DrawLine(blackPen1, 257, 210, 257, 271);
graphicImage.DrawLine(blackPen1, 304, 210, 304, 271);
//Top Rectangle - Label Text
graphicImage.DrawString("Shipper's Information:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 43));
graphicImage.DrawString("Receiver's Information:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 79));
graphicImage.DrawString("Origin", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(263, 43));
graphicImage.DrawString("Destination", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(263, 79));
graphicImage.DrawString("Time-definite type", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(263, 131));
graphicImage.DrawString("Total packages", new Font("Arial", 6), SystemBrushes.WindowText, new Point(10, 213));
graphicImage.DrawString("Total Actual weight", new Font("Arial", 6), SystemBrushes.WindowText, new Point(10, 228));
graphicImage.DrawString("Total Chargeable weight", new Font("Arial", 6), SystemBrushes.WindowText, new Point(10, 243));
graphicImage.DrawString("Freight Charges", new Font("Arial", 6), SystemBrushes.WindowText, new Point(10, 258));
graphicImage.DrawString("Additional Service", new Font("Arial", 6), SystemBrushes.WindowText, new Point(180, 213));
graphicImage.DrawString("Charges", new Font("Arial", 6), SystemBrushes.WindowText, new Point(264, 213));
graphicImage.DrawString("Total Charges", new Font("Arial", 6), SystemBrushes.WindowText, new Point(310, 213));
graphicImage.DrawString("Payment Information:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 275));
graphicImage.DrawString("Credit Account No.:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 290));
graphicImage.DrawString("3rd Party District code:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 305));
graphicImage.DrawString("Receiver's Signature:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(263, 275));
graphicImage.DrawString("Delivery Date:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(263, 305));
graphicImage.DrawString("Remarks:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 327));
//Bottom Rectangle - Draw Box
Rectangle bottomRect = new Rectangle(5, 349, 367, 211);
graphicImage.DrawRectangle(blackPen1, bottomRect);
//Bottom Rectangle - Horizontial Lines
graphicImage.DrawLine(blackPen1, 258, 377, 372, 377);
graphicImage.DrawLine(blackPen1, 5, 401, 258, 401);
graphicImage.DrawLine(blackPen1, 5, 468, 372, 468);
graphicImage.DrawLine(blackPen1, 5, 528, 372, 528);
//Bottom Rectangle - Vertical Lines
graphicImage.DrawLine(blackPen1, 258, 349, 258, 560);
//Bottom Rectangle - Label Text
graphicImage.DrawString("Shipment Type:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 352));
graphicImage.DrawString("Description of Contents:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 380));
graphicImage.DrawString("Declared value for Customs:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 420));
graphicImage.DrawString("Country of Origin:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 450));
graphicImage.DrawString("Shipper's Information:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 404));
graphicImage.DrawString("Receivers's Information:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 471));
graphicImage.DrawString("Total Charges:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 471));
graphicImage.DrawString("Payment Information:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 495));
graphicImage.DrawString("Customer remarks:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 538));
//Bottom Rectangle - Self Drop Selection Box
Rectangle bottomselectRect1 = new Rectangle(261, 538, 12, 12);
graphicImage.DrawRectangle(blackPen1, bottomselectRect1);
//Bottom Rectangle - Self Pickup Selection Box
Rectangle bottomselectRect2 = new Rectangle(313, 538, 12, 12);
graphicImage.DrawRectangle(blackPen1, bottomselectRect2);
graphicImage.DrawString("Self-drop:", new Font("Arial", 5), SystemBrushes.WindowText, new Point(276, 541));
graphicImage.DrawString("Self-pickup:", new Font("Arial", 5), SystemBrushes.WindowText, new Point(328, 541));
HttpContext.Current.Response.ContentType = "image/png";
bitMapImage.Save("test_label_" + dttime + ".png", ImageFormat.Png);
blackPen0.Dispose();
blackPen1.Dispose();
blackPen2.Dispose();
blackPen3.Dispose();
graphicImage.Dispose();
bitMapImage.Dispose();
This is only a partial answer, but it may help. Here is what your image is:
Image Dinensions: 377 x 566 Pixels
10.19 x 15.30 Cm
Pixels Per cm: 37
It might help to know what your output device(s) use, but most inkjet printers I have used are happy with 300 pixels per inch (or some multiple of 300 dpi). Other resolutions would have to be scaled, which could be disastrous for such fine detail.
Do you have a graphics program you can use to modify the resolution and scaling of your PNG so you can experiment without having to keep changing your program? (I'm using an ancient version of the no-longer-available Paint Shop Pro, but I also have Corel Photo Paint which would also do the job.) If you don't have anything, you might try gimp (free bitmap software).
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?
I'm creating a label with Graphics and printing it with PrintDocument, before i didn't had any problems because the information on the label was repeated multiple times so i would just set copies and everything would work fine.
But now each label has a different information so it freezes the ui because i have to loop PrintDocument.Print() multiple times instead of setting copies.
i tried:
Task t = new Task(() =>
{
for (int i = 0; i < Copies; i++)
{
printDocument1.Print();
Label_Copies++;
}
});
t.Start();
I'm drawing the label on printDocument1_PrintPage with this code:
int base_y = 5;
int base_x = 7;
int fontsize_bold = 8;
int fontsize_regular = 7;
RectangleF baserect = new RectangleF(base_x, base_y + 20, 0, 0);
SolidBrush whiteBrush = new SolidBrush(System.Drawing.Color.White);
SolidBrush blackBrush = new SolidBrush(System.Drawing.Color.Black);
string font = "Cabriolli";
Pen mypen = new Pen(blackBrush);
e.Graphics.FillRectangle(whiteBrush, new Rectangle(0, 0, 320, 130));
//e.Graphics.DrawRectangle(mypen, 1, 1, 225, 140);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawString("REMETENTE:",
new Font(font, fontsize_regular, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x, base_y, 0, 0));
base_y += 10;
e.Graphics.DrawString("BETA COMERCIAL IMPORTADORA LTDA",
new Font(font, fontsize_bold, System.Drawing.FontStyle.Bold),
Brushes.Black, new RectangleF(base_x, base_y, 0, 0));
base_y += 15;
e.Graphics.DrawString("DESTINATARIO:",
new Font(font, fontsize_regular, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x, base_y, 0, 0));
base_y += 10;
e.Graphics.DrawString(Etiqueta_Destinatario, // *cliente
new Font(font, fontsize_bold, System.Drawing.FontStyle.Bold),
Brushes.Black, new RectangleF(base_x, base_y, 0, 0));
base_y += 15;
e.Graphics.DrawString("NOTA FISCAL:",
new Font(font, fontsize_regular, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x, base_y + 3, 0, 0));
e.Graphics.DrawString(Etiqueta_Nota, // *nota
new Font(font, 10, System.Drawing.FontStyle.Bold),
Brushes.Black, new RectangleF(base_x + 68, base_y, 0, 0));
base_y += 15;
e.Graphics.DrawString("PEDIDO:",
new Font(font, fontsize_regular, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x, base_y + 3, 0, 0));
e.Graphics.DrawString(Etiqueta_Pedido, // *pedido
new Font(font, 10, System.Drawing.FontStyle.Bold),
Brushes.Black, new RectangleF(base_x + 43, base_y, 0, 0));
base_y += 15;
e.Graphics.DrawString("Etiqueta numero:",
new Font(font, fontsize_regular, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x + 140, base_y - 20, 0, 0));
if (Copias.Checked)
{
e.Graphics.DrawString(Etiqueta_Copias.ToString(),
new Font(font, 15, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x + 140, base_y, 0, 0));
}
else
{
e.Graphics.DrawString(Etiqueta_Copia.ToString(),
new Font(font, 15, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x + 140, base_y, 0, 0));
}
e.Graphics.DrawString("VOLUMES:",
new Font(font, fontsize_regular, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x, base_y + 3, 0, 0));
e.Graphics.DrawString(peças_textbox.Text, // *quantidade
new Font(font, 10, System.Drawing.FontStyle.Bold),
Brushes.Black, new RectangleF(base_x + 53, base_y, 0, 0));
base_y += 25;
e.Graphics.DrawString("TRANSPORTADORA:",
new Font(font, fontsize_regular, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x, base_y, 0, 0));
base_y += 14;
e.Graphics.DrawString(nota_transportadora_combobox.Text, // *transportadora
new Font(font, 10, System.Drawing.FontStyle.Bold),
Brushes.Black, new RectangleF(base_x, base_y, 0, 0));
whiteBrush.Dispose();
blackBrush.Dispose();
mypen.Dispose();
but it doesn't work is there a way to fix it?
-the information comes from the ui
-500~ labels
-the only information that changes from label to label in those copies is
if (Copias.Checked)
{
e.Graphics.DrawString(Etiqueta_Copias.ToString(),
new Font(font, 15, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x + 140, base_y, 0, 0));
}
else
{
e.Graphics.DrawString(Etiqueta_Copia.ToString(),
new Font(font, 15, System.Drawing.FontStyle.Regular),
Brushes.Black, new RectangleF(base_x + 140, base_y, 0, 0));
}
its basically a counter for the label number...
As I see it, your code, if we ignore the printer's spooling side, is pure WinForms UI.
Since that the work is multiplied, let's say by a 100 copies, it becomes too much Continous UI.
Tasking isn't helping you because I think the printing side is "fire and forget", so even if the printing took 30 seconds per sticker, the printing side would return immediately, and let the UI start it's heavy work on the next sticker, almost immediately after it finishes the last one.
let's say the UI has to work 1 second per sticker, you are looking at a 100 seconds UI blocking...
My suggestion:
Rely on the fact that the printing behind takes 20 seconds: Launch the printing using a timer instead of a loop. Set it to 5, 10 or 20 seconds (match with your printer's speed). Each time you will fire the timer, it will UI process 1 sticker only, and then rest in peace for 5, 10, or 20 seconds...