| |
VB.NET - Ein- und UmsteigerDruck über mehrere Seiten..... | | | Autor: Mctotti | Datum: 06.09.20 18:19 |
| Hallo zusammen,
Ich möchte gerne Daten aus meiner DB drucken, das funktioniert auch alles richtig gut. Sofern es wenige Datensätze sind ( die auf eine seite passen). Aber wenn viel mehr Datensätze zu Drucken sind , dann passen sie nicht mehr auf eine Seite ( ist ja klar). Wie kann ich dem genau sagen das er auf der nächsten seite weiter drucken soll. Ich weiss mit e.HasMorePages soll es gehen. Ich versuch nun schon seit Tagen es alleine hinzubekommen. Habe schon soviel ausprobiert aber keine saubere Lösung gefunden / hingekriegt.
Ich habe hier mal meinen Code gepostet wo ihr sehen könnt wie ich die Daten aus der DB aufs Papier bringe.
Wie gesagt mit wenigen Datensätzen funzt es super. Aber dann hört es bei mir aber auch schon auf.
Ich wäre für Hilfe oder Anregungen sehr dankbar.
Private Sub PrintDocument3_PrintPage(sender As Object, e As _
PrintPageEventArgs) Handles PrintDocument3.PrintPage
Dim sql As String
Dim cmd As New OleDb.OleDbCommand
Dim dt As New DataTable
Dim da As New OleDb.OleDbDataAdapter
' Text Ausrichtung
text_rechts.Alignment = StringAlignment.Far 'far= rechts ausgerichtet
text_links.Alignment = StringAlignment.Near 'near ist links
' ausgerichtet
text_mitte.Alignment = StringAlignment.Center ' center ist
' mittig ausgerichtet
con.Open()
sql = "select * from kontakte order by nachname "
cmd.Connection = con
cmd.CommandText = sql
da.SelectCommand = cmd
x_achse = 100
y_achse = 500
e.Graphics.DrawString("Kontaktliste", New Font("Times New Roman", 26, _
FontStyle.Bold), Brushes.Black, y_achse, x_achse, text_links)
'erste zahl startpunkt von links ( Y achse ),zweite zahl ist die höhe
' von oben ( x achse ),dritte zahl ist der endpunkt ( y achse),vierte
' zahl ist die höhe von oben ( x achse )
e.Graphics.DrawLine(Pens.Black, 500, 150, 700, 150)
x_achse = 200
y_achse = 40
da.Fill(dt)
For Each row As DataRow In dt.Rows
e.Graphics.DrawString(row("vorname"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse, x_achse, _
text_links)
e.Graphics.DrawString(row("nachname"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 100, x_achse, _
text_links)
e.Graphics.DrawString(row("strasse"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 230, x_achse, _
text_links)
e.Graphics.DrawString(row("plz"), New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 410, x_achse, _
text_links)
e.Graphics.DrawString(row("wohnort"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 500, x_achse, _
text_links)
e.Graphics.DrawString(row("telefon"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 650, x_achse, _
text_links)
e.Graphics.DrawString(row("mobil"), New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 750, x_achse, _
text_links)
e.Graphics.DrawString(row("email"), New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 850, x_achse, _
text_links)
e.Graphics.DrawString(row("geburtstag"), New Font("Times New" & _
"Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + 1000, _
x_achse, text_links)
x_achse = x_achse + 30
Next
e.Graphics.DrawString("Ausdruck vom :" & " " & aktuellesDatum, New Font( _
"Times New Roman", 10, FontStyle.Regular), Brushes.Black, 60, 750, _
text_links)
con.Close()
End Sub | |
Re: Druck über mehrere Seiten..... | | | Autor: Mctotti | Datum: 07.09.20 19:50 |
| Hallo, habe es jetzt mal so gemacht und er macht es ja auch, nur immer auf der selben seite, er fängt keine neue Seite an sondern überschreibt die ersten gedruckten Sätze.
Warum macht er keine mehreren Seiten auf.... Ich habe schon einen Haltepunkt gesetzt und alles schrittweise durchlaufen lassen. Das passt alles soweit.....Ich komm einfach nicht drauf warum er die seiten nicht wechselt bzw. neu erstellt.
For Each row As DataRow In dt.Rows
e.Graphics.DrawString(row("vorname"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse, x_achse, _
text_links)
e.Graphics.DrawString(row("nachname"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 100, x_achse, _
text_links)
e.Graphics.DrawString(row("strasse"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 230, x_achse, _
text_links)
e.Graphics.DrawString(row("plz"), New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 410, x_achse, _
text_links)
e.Graphics.DrawString(row("wohnort"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 500, x_achse, _
text_links)
e.Graphics.DrawString(row("telefon"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 650, x_achse, _
text_links)
e.Graphics.DrawString(row("mobil"), New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 750, x_achse, _
text_links)
e.Graphics.DrawString(row("email"), New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 850, x_achse, _
text_links)
e.Graphics.DrawString(row("geburtstag"), New Font("Times New" & _
"Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + 1000, _
x_achse, text_links)
x_achse = x_achse + 30
If x_achse >= 630 Then
e.HasMorePages = True
x_achse = 200
Else
e.HasMorePages = False
End If
Next | |
Re: Druck über mehrere Seiten..... | | | Autor: Manfred X | Datum: 07.09.20 20:28 |
| Schau Dir die Druckschleife im Beispiel an.
Du kannst nicht mit ForEach arbeiten, sonst startest Du auf jeder
Seite neu.
Du musst den Schleifenindex für Deine Rows hochzählen und eine
While-Schleife benutzen,die eine entsprechende Abbruchbedingungen hat. | |
Re: Druck über mehrere Seiten..... | | | Autor: Mctotti | Datum: 09.09.20 18:20 |
| Hallo, entweder übersehe ich was oder ich schnall das einfach nicht.
Habe jetzt eine while - Schleife drin mit einer Abfrage.
index und aktuellezeile sind beide mit Integer deklariert
Gesamtzeilen = anzahl der Datensätze aus der Datenbank( mit count abgefragt)
Ich habe immer noch das gleiche Problem mit den Seiten, Schleife läuft bis index 16 erreicht, dann geht er auf e.HasMorePages =true, index wird wieder auf 0 gesetzt.
x_achse wird auf anfangswert gesetzt damit er auf der nächsten seite an der richtigen Position weiter druckt
Seitenzähler ist noch unbenutzt, soll aber später auf den Seiten die Seitennummer anzeigen
Ich verstehe es einfach nicht warum er nicht die nächste seite druckt.
Unter vb 6 war das so einfach....oder stell ich mich einfach zu dusselig an?
Ich habe mir das Projekt angeschaut, aber irgendwie blick ich da nicht ganz durch.
While AktuelleZeile < GesamtZeilen
e.Graphics.DrawString("vorname", New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse, x_achse, text_links)
e.Graphics.DrawString("nachname", New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 100, x_achse, _
text_links)
e.Graphics.DrawString("strasse", New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 230, x_achse, _
text_links)
e.Graphics.DrawString("plz", New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 410, x_achse, _
text_links)
e.Graphics.DrawString("wohnort", New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 500, x_achse, _
text_links)
e.Graphics.DrawString("telefon", New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 650, x_achse, _
text_links)
e.Graphics.DrawString("mobil", New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 750, x_achse, _
text_links)
e.Graphics.DrawString("email", New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 850, x_achse, _
text_links)
e.Graphics.DrawString("geburtstag", New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 1000, x_achse, _
text_links)
x_achse = x_achse + 30
index = index + 1
AktuelleZeile = AktuelleZeile + 1
If index >= 16 Then
e.HasMorePages = True
index = 0
x_achse = 200
Seitenzähler = Seitenzähler + 1
Else
Seitenzähler = 1
End If
End While
e.HasMorePages = False
Beitrag wurde zuletzt am 09.09.20 um 18:28:32 editiert. | |
Re: Druck über mehrere Seiten..... | | | Autor: Manfred X | Datum: 09.09.20 18:37 |
| Wo und wie hast Du die Variable "AktuelleZeile" deklariert?
Im Beispiel ist das eine Static-Variable, die ihren Wert beibehält
zwischen zwei Aufrufen der Druckroutine.
Mit Deinem Code kann ich nichts anfangen. Der ist unvollständig
und sinnlos.
Du musst den Code aus meinem Beispiel übernehmen und statt Listviewitems
die Datatatable-Rows gemäß RowIndex = AktuelleZeile drucken
(oder die Zeilenfolge aus der Bindingsource abfragen). | |
Re: Druck über mehrere Seiten..... | | | Autor: Mctotti | Datum: 14.09.20 16:37 |
| Hallo, hat ein bischen gedauert aber ich habe es hinbekommen, ich poste hier mal meinen Code damit ihr seht wie ich das gelöst habe. Es druckt jetzt eine oder mehrere Seiten, je nach Bedarf.So ist die Grundfunktion fertig. Das ist jetzt die Rohfassung, werde es noch ein bischen ausbauen und perfektionieren.
Vielen Dank für eure tolle Unterstützung und Anregungen
Wenn Bedarf entsteht poste ich später auch gerne die gesamte Druckgeschichte.
firstrow=0 ist als Integer deklariert
16 ist Zeilenanzahl die aufs Blatt passen ( Querformat )
For i As Integer = firstRow To dt.Rows.Count - 1
If i - firstRow < 16 Then
e.Graphics.DrawString(dt.Rows(i)("vorname"), New Font("Times" & _
"New Roman", 10, FontStyle.Regular), Brushes.Black, y_achse, _
x_achse, text_links)
e.Graphics.DrawString(dt.Rows(i)("nachname"), New Font("Times" & _
"New Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + _
100, x_achse, text_links)
e.Graphics.DrawString(dt.Rows(i)("strasse"), New Font("Times" & _
"New Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + _
230, x_achse, text_links)
e.Graphics.DrawString(dt.Rows(i)("plz"), New Font("Times New" & _
"Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + 410, _
x_achse, text_links)
e.Graphics.DrawString(dt.Rows(i)("wohnort"), New Font("Times" & _
"New Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + _
500, x_achse, text_links)
e.Graphics.DrawString(dt.Rows(i)("telefon"), New Font("Times" & _
"New Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + _
650, x_achse, text_links)
e.Graphics.DrawString(dt.Rows(i)("mobil"), New Font("Times New" & _
"Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + 750, _
x_achse, text_links)
e.Graphics.DrawString(dt.Rows(i)("email"), New Font("Times New" & _
"Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + 850, _
x_achse, text_links)
e.Graphics.DrawString(dt.Rows(i)("geburtstag"), New Font("Times" & _
"New Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + _
1000, x_achse, text_links)
x_achse = x_achse + 30 'abstand von der vorherigen zeile
Else
firstRow = i
e.HasMorePages = True
cn.Close()
Exit Sub
End If
Next
e.Graphics.DrawString("Ausdruck vom :" & " " & aktuellesDatum, New Font( _
"Times New Roman", 10, FontStyle.Regular), Brushes.Black, 60, 750, _
text_links)
cn.Close()
Me.Close() | |
| Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
|
|
sevOutBar 4.0
Vertikale Menüleisten á la Outlook
Erstellen von Outlook ähnlichen Benutzer- interfaces - mit beliebig vielen Gruppen und Symboleinträgen. Moderner OfficeXP-Style mit Farbverläufen, Balloon-Tips, u.v.m. Weitere InfosTipp des Monats Access-Tools Vol.1
Über 400 MByte Inhalt
Mehr als 250 Access-Beispiele, 25 Add-Ins und ActiveX-Komponenten, 16 VB-Projekt inkl. Source, mehr als 320 Tipps & Tricks für Access und VB
Nur 24,95 EURWeitere Infos
|