C# Listview drucken

martl92

Lieutenant
Registriert
Feb. 2009
Beiträge
598
Hallo @ all

Ich habe eine Listview mit 6 Spalten und nun möchte ich über einen Button eine Funktion zum Ausdrucken hinzufügen. Ich stehe auf der Leitung, da ich bisher noch nie eine drucken funktion programmiert habe. Ich hoffe jemand kann mir weiter helfen und mir die Schritte verständlich erklären, denn die Ergebnisse bei google haben mir nicht weitergeholfen.

Zusätzliche Frage:
Ist eine Druckvorschau schwierig? Vielleicht hat jemand ein paar tipps zu diesem vorhaben.

Danke schon mal im vorraus an alle! :)

mfg
 
Ok danke für den Link. Hat geholfen :)!!!

EDIT: Habe jetzt alles programmiert (Vorschau, Settings usw.) doch ich muss dem PrintDocument Objekt noch die Listview übertragen, damit ja auch diese Liste gedruckt wird. Doch ich weiß jetzt nicht wie man das macht, sodass die Listview gedruckt wird und angezeigt wird. Jemand ne Idee?

mfg
Ergänzung ()

Niemand ne Idee?
 
Zuletzt bearbeitet:
Habe es jetzt mal so gemacht:

int y = 100, item = 0;
int xuber = 250, yuber = 40;
int x0 = 80, x1 = 260, x2 = 440, x3 = 600, x4 = 760, x5 = 960;
Font tableFont = new Font("Arial", 16);

e.Graphics.DrawString("Teilnehmerliste: " + filename, new Font("Calibri", 26), Brushes.DarkRed, xuber, yuber);
e.Graphics.DrawString("Startnummer", new Font("Times New Roman", 18, FontStyle.Bold), Brushes.Black, x0, y);
e.Graphics.DrawString("Nachname", new Font("Times New Roman", 18, FontStyle.Bold), Brushes.Black, x1, y);
e.Graphics.DrawString("Vorname", new Font("Times New Roman", 18, FontStyle.Bold), Brushes.Black, x2, y);
e.Graphics.DrawString("Geschlecht", new Font("Times New Roman", 18, FontStyle.Bold), Brushes.Black, x3, y);
e.Graphics.DrawString("Geburtsdatum", new Font("Times New Roman", 18, FontStyle.Bold), Brushes.Black, x4, y);
e.Graphics.DrawString("Sportverein", new Font("Times New Roman", 18, FontStyle.Bold), Brushes.Black, x5, y);
y = y + 40;

while (item < listView1.Items.Count)
{
string str;
str = listView1.Items[item].Text;
e.Graphics.DrawString(str, tableFont, Brushes.Black, x0, y);
str = listView1.Items[item].SubItems[1].Text;
e.Graphics.DrawString(str, tableFont, Brushes.Black, x1, y);
str = listView1.Items[item].SubItems[2].Text;
e.Graphics.DrawString(str, tableFont, Brushes.Black, x2, y);
str = listView1.Items[item].SubItems[3].Text;
e.Graphics.DrawString(str, tableFont, Brushes.Black, x3+50, y);
str = listView1.Items[item].SubItems[4].Text;
e.Graphics.DrawString(str, tableFont, Brushes.Black, x4+20, y);
str = listView1.Items[item].SubItems[5].Text;
e.Graphics.DrawString(str, tableFont, Brushes.Black, x5, y);

int lines;
int cols;
e.Graphics.MeasureString(str, tableFont, new SizeF(900, 150), new StringFormat(), out cols, out lines);
int yc;
yc = y;
yc = yc + tableFont.Height + 2;
y = y + lines * tableFont.Height + 5;
y = Math.Max(y, yc);
item++;
}

Kompliziert aber es funktioniert zumindest bis die Einträge nicht mehr auf die Seite passen. Dann wird noch keine neue Seite genommen, aber das sollte noch machbar sein.

mfg
 
Zurück
Oben