printing

ok i have an app that i need to print info from user input in Text boxes and also from labels... i used a streamwriter instance to write the data to a txt file... and it does work and will print with the printdocument... however it prints all on one line without any spaces... is there a new line command i am missing? Also, it prints a blank page b4 it prints the page with text. how do i get rid of that?

my code is as follows:

PrivateSub cmdPrint_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles cmdPrint.Click

Dim thestreamwriterAsNew StreamWriter("C:\Documents and Settings\igiberson\Desktop\VB projects\tryAgain\printFile.txt")

'write the file with the data from labels and textboxes

thestreamwriter.Write(Label10.Text)

thestreamwriter.Write(txtEmpLast.Text)

thestreamwriter.Write(Label1.Text)

thestreamwriter.Write(txtEmpFirst.Text)

thestreamwriter.Write(Label3.Text)

thestreamwriter.Write(txtTitle.Text)

thestreamwriter.Write(Label5.Text)

thestreamwriter.Write(txtDescription.Text)

thestreamwriter.Write(Label2.Text)

thestreamwriter.Write(txtHDate.Text)

thestreamwriter.Write(Label4.Text)

thestreamwriter.Write(comboCampus.Text)

thestreamwriter.Write(Label6.Text)

thestreamwriter.Write(comboSchedule.Text)

thestreamwriter.Write(Label7.Text)

thestreamwriter.Write(comboDept.Text)

'close the file

thestreamwriter.Close()

'print dialog (choose what printer to print to)

PrintDialog1.AllowSomePages =True

PrintDialog1.ShowHelp =True

PrintDialog1.Document = docToPrint

Dim resultAs DialogResult = PrintDialog1.ShowDialog()

If (result = Windows.Forms.DialogResult.OK)Then

docToPrint.Print()

EndIf

'print document(what is acutally being printed)

Try

streamToPrint =New StreamReader("C:\Documents and Settings\igiberson\Desktop\VB projects\tryAgain\printFile.txt")

Try

printFont =New Font("Arial", 12)

Dim pdAsNew PrintDocument()

AddHandler pd.PrintPage,AddressOfMe.pd_PrintPage

pd.Print()

Finally

streamToPrint.Close()

EndTry

Catch exAs Exception

MessageBox.Show(ex.Message)

EndTry

EndSub

' The PrintPage event is raised for each page to be printed.

PrivateSub pd_PrintPage(ByVal senderAsObject,ByVal evAs PrintPageEventArgs)

Dim linesPerPageAsSingle = 0

Dim yPosAsSingle = 0

Dim countAsInteger = 0

Dim leftMarginAsSingle = ev.MarginBounds.Left

Dim topMarginAsSingle = ev.MarginBounds.Top

Dim lineAsString =Nothing

' Calculate the number of lines per page.

linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

' Print each line of the file.

While count < linesPerPage

line = streamToPrint.ReadLine()

If lineIsNothingThen

ExitWhile

EndIf

yPos = topMargin + count * printFont.GetHeight(ev.Graphics)

ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos,New StringFormat())

count += 1

EndWhile

' If more lines exist, print another page.

If (lineIsNotNothing)Then

ev.HasMorePages =True

Else

ev.HasMorePages =False

EndIf

EndSub

[8861 byte] By [IGiberson] at [2007-12-25]
# 1
its because you are using Write instead of WriteLine which writes a new line after the text written to the file. I was going to post some code for your other similar problem which I'm almost kind of done
ahmedilyas at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
oh wow thank you
IGiberson at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...