Problem with printing a page foreach listview.items
-
Hi all! I´m trying to make a barcodeprinting and to make it possible i have to have a page foreach items in my listview. my code look like this: private void button1_Click(object sender, EventArgs e) { if (checkBox1.Checked == true) { PrintDialog theDialog = new PrintDialog(); theDialog.Document = printDocument1; if (theDialog.ShowDialog() == DialogResult.OK) { printDocument1.DocumentName = listView1.Items.Count.ToString(); printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage); printDocument1.Print(); } } } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { foreach (ListViewItem lvi in listView1.Items) { DateTime dt = DateTime.Now; string doktyp = "278"; Font font = new Font("3 of 9 Barcode", 20); int St = Convert.ToInt32(domainUpDown1.Text); Font font1 = new Font("Arial", St); Font font2 = new Font("Arial", 10); float x = 120; float y = 100; e.Graphics.DrawString("Jobb: " + label11.Text, font2, new SolidBrush(Color.Black), x + 500, y - 50); e.Graphics.DrawString("Användare: " + label12.Text, font2, new SolidBrush(Color.Black), x + 500, y - 35); e.Graphics.DrawString(dt.ToString("yyyy-dd-MM HH:mm:ss"), font2, new SolidBrush(Color.Black), x + 500, y - 20); e.Graphics.DrawString("*" + lvi.SubItems[1].Text + "*", font, new SolidBrush(Color.Black), x, y + 85); e.Graphics.DrawString("*" + lvi.SubItems[1].Text + "*", font, new SolidBrush(Color.Black), x, y + 105); e.Graphics.DrawString("*" + lvi.SubItems[1].Text + "*", font, new SolidBrush(Color.Black), x, y + 125); e.Graphics.DrawString(lvi.SubItems[1].Text, font1, new SolidBrush(Color.Black), x, y + 145); } } With this code it overwhrites all the items in one page. Thanks! Best Regards André
-
Hi all! I´m trying to make a barcodeprinting and to make it possible i have to have a page foreach items in my listview. my code look like this: private void button1_Click(object sender, EventArgs e) { if (checkBox1.Checked == true) { PrintDialog theDialog = new PrintDialog(); theDialog.Document = printDocument1; if (theDialog.ShowDialog() == DialogResult.OK) { printDocument1.DocumentName = listView1.Items.Count.ToString(); printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage); printDocument1.Print(); } } } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { foreach (ListViewItem lvi in listView1.Items) { DateTime dt = DateTime.Now; string doktyp = "278"; Font font = new Font("3 of 9 Barcode", 20); int St = Convert.ToInt32(domainUpDown1.Text); Font font1 = new Font("Arial", St); Font font2 = new Font("Arial", 10); float x = 120; float y = 100; e.Graphics.DrawString("Jobb: " + label11.Text, font2, new SolidBrush(Color.Black), x + 500, y - 50); e.Graphics.DrawString("Användare: " + label12.Text, font2, new SolidBrush(Color.Black), x + 500, y - 35); e.Graphics.DrawString(dt.ToString("yyyy-dd-MM HH:mm:ss"), font2, new SolidBrush(Color.Black), x + 500, y - 20); e.Graphics.DrawString("*" + lvi.SubItems[1].Text + "*", font, new SolidBrush(Color.Black), x, y + 85); e.Graphics.DrawString("*" + lvi.SubItems[1].Text + "*", font, new SolidBrush(Color.Black), x, y + 105); e.Graphics.DrawString("*" + lvi.SubItems[1].Text + "*", font, new SolidBrush(Color.Black), x, y + 125); e.Graphics.DrawString(lvi.SubItems[1].Text, font1, new SolidBrush(Color.Black), x, y + 145); } } With this code it overwhrites all the items in one page. Thanks! Best Regards André
Well, that's what you're telling it to do. You don't actually set x anywhere that I can see. It looks to me like all your labels will print in one location, because that's what your code does. x and y need to change to move your labels.
Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
-
Well, that's what you're telling it to do. You don't actually set x anywhere that I can see. It looks to me like all your labels will print in one location, because that's what your code does. x and y need to change to move your labels.
Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.