Hab den Beispielcode von
msdn.microsoft.com/d...aa287530(VS.71).aspx verwendet und auch das Beispielprogramm vom Buch
"Visual C# 2008 Das umfassende Handbuch"
Ich weiss zwar nicht ob man es darf aber ich poste hier mal diesen Beispielcode von microsoft
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
| System.IO.StreamReader fileToPrint; System.Drawing.Font printFont; private void printButton_Click(object sender, EventArgs e) { string printPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop); fileToPrint = new System.IO.StreamReader(printPath + @"\myFile.txt"); printFont = new System.Drawing.Font("Arial", 10); printDocument1.Print(); fileToPrint.Close(); }
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { float yPos = 0f; int count = 0; float leftMargin = e.MarginBounds.Left; float topMargin = e.MarginBounds.Top; string line = null; float linesPerPage = e.MarginBounds.Height/printFont.GetHeight(e.Graphics); while (count < linesPerPage) { line = fileToPrint.ReadLine(); if (line == null) { break; } yPos = topMargin + count * printFont.GetHeight(e.Graphics); e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++; } if (line != null) { e.HasMorePages = true; } } |
Hab mir jetzt überlegt beim erstellen der Textdatei nicht den Tabulator zu verwenden sondern durch eine Funktion ausrechnen wieviele Leerstellen ich von Variable zu Variable einfügen muss.