printing in vb.net [modified] ... resolved
-
When I use the following the code to print in prints on one line. How do I put a hard return at the end of each line. So I can have different more than one line.
Private Sub PrintDocument1_PrintPage_1(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage For Me.counter = 0 To 19 e.Graphics.DrawString(writeline(Me.counter), printFont, _ System.Drawing.Brushes.Black, 10, 10) Next Me.counter End Sub
by using the follow code resolved the issues
Dim strPrint As New StringBuilder For Me.counter = 0 To 19 strPrint.Append(printline(Me.counter) & vbCrLf) Next Me.counter e.Graphics.DrawString(strPrint.ToString, printFont, System.Drawing.Brushes.Black, 10, 10) If System.IO.File.Exists(SaveFileDialog1.FileName) Then printfile = File.OpenText(SaveFileDialog1.FileName) printfile = System.IO.File.OpenText(SaveFileDialog1.FileName) Do Until printfile.Peek = -1 menuitem(printcounter) = printfile.ReadLine e.Graphics.DrawString(printfile.ReadLine, printFont, _ System.Drawing.Brushes.Black, 10, 10) printcounter = printcounter + 1 Loop printfile.Close() End If
now the problem is tab spacing.
modified on Thursday, March 11, 2010 1:40 PM
-
When I use the following the code to print in prints on one line. How do I put a hard return at the end of each line. So I can have different more than one line.
Private Sub PrintDocument1_PrintPage_1(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage For Me.counter = 0 To 19 e.Graphics.DrawString(writeline(Me.counter), printFont, _ System.Drawing.Brushes.Black, 10, 10) Next Me.counter End Sub
by using the follow code resolved the issues
Dim strPrint As New StringBuilder For Me.counter = 0 To 19 strPrint.Append(printline(Me.counter) & vbCrLf) Next Me.counter e.Graphics.DrawString(strPrint.ToString, printFont, System.Drawing.Brushes.Black, 10, 10) If System.IO.File.Exists(SaveFileDialog1.FileName) Then printfile = File.OpenText(SaveFileDialog1.FileName) printfile = System.IO.File.OpenText(SaveFileDialog1.FileName) Do Until printfile.Peek = -1 menuitem(printcounter) = printfile.ReadLine e.Graphics.DrawString(printfile.ReadLine, printFont, _ System.Drawing.Brushes.Black, 10, 10) printcounter = printcounter + 1 Loop printfile.Close() End If
now the problem is tab spacing.
modified on Thursday, March 11, 2010 1:40 PM
You need to add a line feed char at the end of each line. Try this :
For Me.counter = 0 To 19 e.Graphics.DrawString(WriteLine(Me.counter & vbCrLf), printFont, System.Drawing.Brushes.Black, 10, 10) Next Me.counter
Hope this helps. [EDIT] Sorry that won't work either. That will print one line on top of another. The best eway to do this is with a stringbuilder like this :
Dim strPrint As New StringBuilder For Me.counter = 0 To 19 strPrint.Append(counter & vbCrLf) Next Me.counter e.Graphics.DrawString(strPrint.ToString, New Font("Ariel", 12), System.Drawing.Brushes.Black, 10, 10)
you will need to import System.Text into your class. Hope THIS helps. [/EDIT]
modified on Wednesday, March 10, 2010 9:12 PM
-
You need to add a line feed char at the end of each line. Try this :
For Me.counter = 0 To 19 e.Graphics.DrawString(WriteLine(Me.counter & vbCrLf), printFont, System.Drawing.Brushes.Black, 10, 10) Next Me.counter
Hope this helps. [EDIT] Sorry that won't work either. That will print one line on top of another. The best eway to do this is with a stringbuilder like this :
Dim strPrint As New StringBuilder For Me.counter = 0 To 19 strPrint.Append(counter & vbCrLf) Next Me.counter e.Graphics.DrawString(strPrint.ToString, New Font("Ariel", 12), System.Drawing.Brushes.Black, 10, 10)
you will need to import System.Text into your class. Hope THIS helps. [/EDIT]
modified on Wednesday, March 10, 2010 9:12 PM
I have tried hard coding the hard return the string array but still did not work.
-
I have tried hard coding the hard return the string array but still did not work.
Sorry, I don't quite get what you mean, although I tried a test and my second example works perfectly. The only thing was a typo in the font declaration, "Ariel" should be "Arial".
-
When I use the following the code to print in prints on one line. How do I put a hard return at the end of each line. So I can have different more than one line.
Private Sub PrintDocument1_PrintPage_1(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage For Me.counter = 0 To 19 e.Graphics.DrawString(writeline(Me.counter), printFont, _ System.Drawing.Brushes.Black, 10, 10) Next Me.counter End Sub
by using the follow code resolved the issues
Dim strPrint As New StringBuilder For Me.counter = 0 To 19 strPrint.Append(printline(Me.counter) & vbCrLf) Next Me.counter e.Graphics.DrawString(strPrint.ToString, printFont, System.Drawing.Brushes.Black, 10, 10) If System.IO.File.Exists(SaveFileDialog1.FileName) Then printfile = File.OpenText(SaveFileDialog1.FileName) printfile = System.IO.File.OpenText(SaveFileDialog1.FileName) Do Until printfile.Peek = -1 menuitem(printcounter) = printfile.ReadLine e.Graphics.DrawString(printfile.ReadLine, printFont, _ System.Drawing.Brushes.Black, 10, 10) printcounter = printcounter + 1 Loop printfile.Close() End If
now the problem is tab spacing.
modified on Thursday, March 11, 2010 1:40 PM
-
Sorry, I don't quite get what you mean, although I tried a test and my second example works perfectly. The only thing was a typo in the font declaration, "Ariel" should be "Arial".
why are we appending the counter which is an index of the wriline string array.
Dim strPrint As New StringBuilder For Me.counter = 0 To 19 strPrint.Append(counter & vbCrLf) Next Me.counter e.Graphics.DrawString(strPrint.ToString, New Font("Ariel", 12), System.Drawing.Brushes.Black, 10, 10)
should be <pre><code> Dim strPrint As New StringBuilder For Me.counter = 0 To 19 strPrint.Append(writeline(me.counter) & vbCrLf) Next Me.counter e.Graphics.DrawString(strPrint.ToString, New Font("Ariel", 12), System.Drawing.Brushes.Black, 10, 10)</code></pre>