Chris-Ramsey
New member
- Joined
- Mar 28, 2008
- Messages
- 4
- Programming Experience
- Beginner
Hi, Im sorry if there is a more specific place to put this but I am fairly new, both to this forum and to programming.
I have made an application very similar to MS notepad although you can have different fonts, colours etc. I have every button in my toolbar working apart from the print.
I managed to find some code on the web to help me with this. I am unable to print but it will print a blank page.
Here is the code:
I am using textbox1 as my textbox. I also have a printdialog and printdocument control on my form. (PrintDialog1 and PrintDocument1)
Can anyone spot anything they think is wrong? Sorry, if i havent explained my problem clearly.
thanks in advance
I have made an application very similar to MS notepad although you can have different fonts, colours etc. I have every button in my toolbar working apart from the print.
I managed to find some code on the web to help me with this. I am unable to print but it will print a blank page.
Here is the code:
VB.NET:
Private Sub PrintFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PrintToolStripButton.Click
PrintDialog1.Document = PrintDocument1
Dim strText As String = Me.TextBox1.Text
Dim myReader = New IO.StringReader(strText)
If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.PrintDocument1.Print()
End If
End Sub
Private Sub ThePrintDocument_PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPosition As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing
Dim printFont As Font = Me.TextBox1.Font
Dim myBrush As New SolidBrush(Color.Black)
Dim strText As String = Me.TextBox1.Text
Dim myReader = New IO.StringReader(strText)
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
While count < linesPerPage And Not ((line <= myReader.ReadLine()) Is Nothing)
ev.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPosition, New StringFormat())
count += 1
End While
ev.HasMorePages = False
myBrush.Dispose()
End Sub
I am using textbox1 as my textbox. I also have a printdialog and printdocument control on my form. (PrintDialog1 and PrintDocument1)
Can anyone spot anything they think is wrong? Sorry, if i havent explained my problem clearly.
thanks in advance
Last edited: