473,379 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to print text in multiline textbox ?

I am using VB.NET 2008.
I have a multiline textbox on the form that I would like to print when the
user click on the "Print" button.
With my codes below, when the text are in more than 1 page (say 3 pages) of
the textbox, when it prints the text in the text box, the 2nd and 3rd pages
are printed on the same page with the 1st page.
So, instead of printing 3 pages, it prints 1 page with the text from page 2
and 3 are printed on top of each other.
Please let me know how I can do it correctly.
Thank you.

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click
prnDoc.DefaultPageSettings.Landscape = True
Dim strText As String = txtLog.Text
myReader = New StringReader(strText)
prnDoc.Print()
End Sub

Private Sub prnDoc_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles prnDoc.PrintPage
Dim linesPerPage As Single = 0
Dim yPosition As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top
Dim line As String = Nothing
Dim printFont As Font = txtLog.Font
Dim myBrush As New SolidBrush(Color.Black)

linesPerPage = e.MarginBounds.Height /
printFont.GetHeight(e.Graphics)
While count < linesPerPage
line = myReader.ReadLine()
If (line Is Nothing) Then
Exit While
Else
yPosition = topMargin + count *
printFont.GetHeight(e.Graphics)
e.Graphics.DrawString(line, printFont, myBrush, leftMargin,
yPosition, New StringFormat())
count += 1
If count >= linesPerPage Then
e.HasMorePages = True
count = 0
End If
End If
End While
e.HasMorePages = False
myBrush.Dispose()
Jun 27 '08 #1
1 7500
Never mind.
I got my answer (thanks to a posting by Andy on www.vbforums.com).
This is how my code look like now:

Private Sub prnDoc_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles prnDoc.PrintPage
Dim linesPerPage As Single = 0
Dim yPosition As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top
Dim line As String = Nothing
Dim printFont As Font = txtLog.Font
Dim myBrush As New SolidBrush(Color.Black)
linesPerPage = e.MarginBounds.Height /
printFont.GetHeight(e.Graphics)
While count < linesPerPage
line = myReader.ReadLine()
If (line Is Nothing) Then
Exit While
Else
yPosition = topMargin + count *
printFont.GetHeight(e.Graphics)
e.Graphics.DrawString(line, printFont, myBrush, leftMargin,
yPosition, New StringFormat())
count += 1
End If
End While
If Not (line Is Nothing) Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
myBrush.Dispose()

"fniles" <fn****@pfmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I am using VB.NET 2008.
I have a multiline textbox on the form that I would like to print when the
user click on the "Print" button.
With my codes below, when the text are in more than 1 page (say 3 pages)
of the textbox, when it prints the text in the text box, the 2nd and 3rd
pages are printed on the same page with the 1st page.
So, instead of printing 3 pages, it prints 1 page with the text from page
2 and 3 are printed on top of each other.
Please let me know how I can do it correctly.
Thank you.

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click
prnDoc.DefaultPageSettings.Landscape = True
Dim strText As String = txtLog.Text
myReader = New StringReader(strText)
prnDoc.Print()
End Sub

Private Sub prnDoc_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles prnDoc.PrintPage
Dim linesPerPage As Single = 0
Dim yPosition As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top
Dim line As String = Nothing
Dim printFont As Font = txtLog.Font
Dim myBrush As New SolidBrush(Color.Black)

linesPerPage = e.MarginBounds.Height /
printFont.GetHeight(e.Graphics)
While count < linesPerPage
line = myReader.ReadLine()
If (line Is Nothing) Then
Exit While
Else
yPosition = topMargin + count *
printFont.GetHeight(e.Graphics)
e.Graphics.DrawString(line, printFont, myBrush, leftMargin,
yPosition, New StringFormat())
count += 1
If count >= linesPerPage Then
e.HasMorePages = True
count = 0
End If
End If
End While
e.HasMorePages = False
myBrush.Dispose()


Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael C | last post by:
Hi all, I'm trying to add lines to a multiline textbox. Here's what I'd like to end up with in the textbox (as an example): Line1 Line2 Line3 I've tried a couple of methods but nothing...
7
by: Joel Finkel | last post by:
Folks, I have a form that has several TextBoxes, some of which have the TextMode set to MultiLine. Each is pre-loaded with data from a database. The user is allowed to modify each entry. The...
2
by: Enzo Marinelli | last post by:
Hello everyone I have a MultiLine TextBox, as follows <asp:TextBo Id="StreetAddress Rows="4 Runat="Server TextMode="MultiLine Width="100%"/
1
by: Olav Tollefsen | last post by:
I have added a MultiLine TextBox to my aspx page: <asp:TextBox ID="TextBox1" runat="server" BorderStyle="None" ReadOnly="True" TextMode="MultiLine"></asp:TextBox> Then I add two lines of text...
0
by: the friendly display name | last post by:
Hi, I have a filled multiline textbox on the site. I can scroll it with IE and Firefox, but under Opera (tested under 7.54, and Opera 8, under "identify as MSIE" and under Opera identification)...
1
by: Flack | last post by:
Hey guys, I have two questions regarding the vertical srollbar of a multiline textbox. 1. I have an "Ok" button that is initially disabled. I want it to be enabled when the user scrolls the...
2
by: Mike | last post by:
I am trying to write a little program for my own use using VB2005 express edition. I have a list of peoples names in a file that I read into an array of strings. I am using a multiline textbox to...
7
by: Anil Gupte | last post by:
I have read a lot about getting lines from a multiline textbox in VB.Net. However, I cannot for the life of me figure out how to write to a multiline textbox. Basically, I have created an array of...
2
by: Nathan Sokalski | last post by:
I have a multiline TextBox that I want to display the text used to create a control in an apsx file. I want each of these to be on a separate line in the TextBox. The only way I know of to place...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.