|
Subject:
|
Print problem in chapter 7
|
|
Posted By:
|
kathy Thisted
|
Post Date:
|
8/4/2004 4:53:47 PM
|
I am having a problem with my print testing in Chapter 7. The Text runs off the page on the right. I end up with a left margin and a top margin of 1.25 inches; however, the last 2 to 3 characters are ending up in the unprintable area on the right, ie. truncated. I am teaching myself to program via books such as yours. Unfortunately my Visual Studio 2003 hasn't arrived and I am trying to use the Visual Basic 2005 Express I downloaded in the interim. I have been able to work around any differences that affect your lesson except the installer section in Chapter 6 which doesn't appear to be provided with the Express version. Is my problem a 2005 problem or do you have a solution to this? I tried to run your copy that I downloaded and it performed the same as mine. I am using Windows XP Home on this machine if that is relevant. Any input would be helpful as I am eager to work on some applications of my own once I learn the code to apply. thank you
|
|
Reply By:
|
Thearon
|
Reply Date:
|
8/12/2004 5:01:45 AM
|
Kathy,
I apologize for taking so long to back to you on this.
I tried printing a large text document using the code from the book and I ran into the same problem that you described. However, since you are using Visual Basic 2005 Express, your printing problems can be corrected with very little code and effort on your part.
Visual Basic 2005 introduced the My namespace which provides a set of base classes that provides quick and easy access to the information that you as a Visual Basic .Net developer are most likely to need. The Computer class is one of these and provides access to the Printers class which provides methods to print documents with a minimal amount of code.
Using the example below, you should be able to print your document from the text box on your form and get the results that you desire.
Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click 'Printing using the My namespace With My.Computer.Printers.DefaultPrinter .WriteLine(txtFile.Text) .Print() End With End Sub
I hope this helps.
Thearon
|
|
Reply By:
|
RobMeade
|
Reply Date:
|
8/12/2004 12:56:35 PM
|
Hi Thearon,
Just out of curiosity, although I didn't experience this problem (for 2 reasons 1) I only had a small text file, and 2) I'm too cheap to actually print it out ) I was wondering what the solution might be for us non VS 2005 users?
If I remember back to that chapter there was some code going on that got the height of the font and then used that to work out how many rows you could fit on each page etc, could a similar approach be used for getting the characters across the page? ie, page width / font width = characters across the page.
This does feel a bit messy, as I'd feel the need to then add code to not chop words in half, so count across, if its in the middle of a word - roll back - find the space - start the next line - start from that word..
Seems a bit of over kill?
Interested to hear anyone's thoughts on this - I'll go and find a bigger text file now and try the example again and see if I get the same - I'm intrigued 
Regards
Rob
|
|
Reply By:
|
Thearon
|
Reply Date:
|
8/13/2004 4:35:28 AM
|
Rob,
I'm going to take the easy route on this one and point you to Microsoft for a good example. Follow this url http://msdn.microsoft.com/vbasic/downloads/samples/ and click on the link 'Download 101 Code Samples for Visual Basic .NET 2003' In there you will find a real good example on printing called 'VB.NET - Windows Forms - Simple Printing'.
Thearon
|
|
Reply By:
|
RobMeade
|
Reply Date:
|
8/14/2004 3:51:51 AM
|
Hi Thearon,
Many thanks for the URL - will check it out now 
Regards
Rob
|
|
Reply By:
|
laljain123
|
Reply Date:
|
4/17/2008 6:57:38 AM
|
I want to create a custom page for printing (with=300,height is depend on lines are printed.).It's a bill print. Print page should be stoped just ofter finishing last line. Help with code in vb 6
|