Announcement

Collapse
No announcement yet.

Mehrere Seiten Drucken?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mehrere Seiten Drucken?

    Hallo,
    Ich habe eine Frage.
    Ich habe meinen PrintPage-Event folgenderweise erstellt.
    Wird eine Seite problemlos gedruckt, wenn aber das Text über Mehrere Seiten hingeht dann wird noch eine Zusätzliche leere Seite bloß mit dem Logo-Bild gedruckt.
    Woran liegt es? Was mache ich falsch?

    [highlight=c#]
    void myPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
    try
    {
    e.HasMorePages = true;
    int items = 0, subItems = 390, lineCount = 0;
    // Logo
    Bitmap imagetoprint = (Bitmap)this.Logo.Image;
    //graphics object
    Graphics gr = e.Graphics;
    // my Font Nr.1
    System.Drawing.Font fnt = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
    // my Font Nr.2
    System.Drawing.Font fntBold = new System.Drawing.Font("Times New Roman", 12, FontStyle.Bold);
    Brush br = Brushes.Black;

    // Header
    gr.DrawImage(imagetoprint, 550, 60, 177, 59);
    gr.DrawString("my Name", fnt, br, 60, 80); // Address
    gr.DrawString("Strasse", fnt, br, 60, 100);
    gr.DrawString("Ort", fnt, br, 60, 130);

    string t2 = "Datum:"+ '\t'+ dateTimePicker1.Text;
    gr.DrawString(t2, fnt, br, 60, 200);

    string t3 = "Erfassungsort:" + '\t' + this.cmbBoxErfassung.Text;
    gr.DrawString(t3, fnt, br, 60, 220);

    string t6 = "Sachbearbeiter:" + '\t' + cmbBoxSachbearbeiter.Text;
    gr.DrawString(t6, fnt, br, 60, 240);

    string t4 = "Auftrag - Nr.: " + this.txtBAuftrag.Text;
    gr.DrawString(t4, fntBold, br, 60, 280);

    string t5 = "Lieferschein: " + this.txtBLieferSchein.Text;
    gr.DrawString(t5, fntBold, br, 60, 300);

    int[] myPixelNumber = new int[7] { 60, 135, 212, 332, 412, 492, 832 }; // Einen Array für feste Abstand zvischen Items
    //ColumnsHeader aus ListView auslesen und zeichnen
    foreach (ColumnHeader cH in listView1.Columns)
    {
    gr.DrawString(cH.Text, fnt, br, myPixelNumber[items], 350);
    items++;
    }
    Pen myPen = new Pen(br);
    PointF a1 = new PointF(60,370);
    PointF a2 = new PointF(800,370);
    gr.DrawLine(myPen,a1,a2);// Eine Trennlinie zeichnen
    // Items und Subitems aus ListView auslesen und zeichnen

    foreach (ListViewItem lvi in listView1.Items)
    {
    items = 0;
    lineCount++;
    foreach (ListViewItem.ListViewSubItem lvi2 in lvi.SubItems)
    {
    gr.DrawString(lvi2.Text, fnt, br, myPixelNumber[items], subItems);
    items++;
    }
    subItems += 20;

    }
    }
    catch (System.Exception printExc)
    {
    MessageBox.Show(printExc.Source + ": " + printExc.Message);
    }
    finally
    {
    e.HasMorePages = false;
    fnt.Dispose();
    fntBold.Dispose();
    br.Dispose();
    }
    }
    [/highlight]
    Zuletzt editiert von codeGenerator; 11.06.2009, 13:13. Reason: Richtig formatieren

  • #2
    So wird das keiner lesen wenn du den Code nicht formatierst um die Lesbarkeit zu erhöhen.

    Du erwartest Hilfe - dann unterstütze die Helfende so gut es geht.


    mfG gü
    "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". - Martin Fowler

    Comment


    • #3
      Tip :
      http://entwickler-forum.de/showthread.php?t=51869

      Comment


      • #4
        Und Einrückungen kennt er auch nicht, wie dort zu sehen. Jürgen

        Comment


        • #5
          Die Frage wird socher noch woanders auftauchen
          "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". - Martin Fowler

          Comment


          • #6
            Hallo alle zusammen,
            mein Problem habe ich schon selber gelöst.
            Es gab mehrere Fehler, jetzt funktioniert es.
            Danke für die Hilfe und Freundlichkeit.

            Comment


            • #7
              @codeGenerator
              Hast ne pn oder bzw. auf diesem Wege:
              Kannste mir deine Lösung mal geben? Würde mich sehr interessieren!

              Comment

              Working...
              X