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.ClickDim thestreamwriterAsNew StreamWriter("C:\Documents and Settings\igiberson\Desktop\VB projects\tryAgain\printFile.txt")'write the file with the data from labels and textboxesthestreamwriter.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 filethestreamwriter.Close()
'print dialog (choose what printer to print to)PrintDialog1.AllowSomePages =
TruePrintDialog1.ShowHelp =
TruePrintDialog1.Document = docToPrint
Dim resultAs DialogResult = PrintDialog1.ShowDialog()If (result = Windows.Forms.DialogResult.OK)ThendocToPrint.Print()
EndIf'print document(what is acutally being printed)TrystreamToPrint =
New StreamReader("C:\Documents and Settings\igiberson\Desktop\VB projects\tryAgain\printFile.txt")TryprintFont =
New Font("Arial", 12)Dim pdAsNew PrintDocument()AddHandler pd.PrintPage,AddressOfMe.pd_PrintPagepd.Print()
FinallystreamToPrint.Close()
EndTryCatch exAs ExceptionMessageBox.Show(ex.Message)
EndTryEndSub' The PrintPage event is raised for each page to be printed.PrivateSub pd_PrintPage(ByVal senderAsObject,ByVal evAs PrintPageEventArgs)Dim linesPerPageAsSingle = 0Dim yPosAsSingle = 0Dim countAsInteger = 0Dim leftMarginAsSingle = ev.MarginBounds.LeftDim topMarginAsSingle = ev.MarginBounds.TopDim 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 < linesPerPageline = streamToPrint.ReadLine()
If lineIsNothingThenExitWhileEndIfyPos = 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)Thenev.HasMorePages =
TrueElseev.HasMorePages =
FalseEndIfEndSub
