Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with printing a page foreach listview.items

Problem with printing a page foreach listview.items

Scheduled Pinned Locked Moved C#
graphicshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andredani
    wrote on last edited by
    #1

    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é

    C 1 Reply Last reply
    0
    • A andredani

      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é

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • C Christian Graus

        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.

        A Offline
        A Offline
        andredani
        wrote on last edited by
        #3

        yes i know.. but i want it to be on print page2 in the same position like page1. Regards!!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups