Printing in VB

Printing Graphics

Outputting graphics to the printer is identical to outputting graphics to a PictureBox. We will cover a few basic commands here, but first lets take a quick look at the CurrentX and CurrentY properties. These were used in the last example, and show where the current coordinates are. Visual Basic automatically change these when it has finished the outputting. For example, imagine you draw a line on a piece of paper - when you have finished drawing, the pen is at the end of the line, not the start. This is the same with the CurrentX and CurrentY properties. If you call the Line method, the line is drawn, and then CurrentX and CurrentY are changed to point to the end of the line. You can then change these if necessary to control where the next text or line is printed.

Note
VB uses the same functions for drawing in picture boxes and outputting to the printer. If you don't want to have to visit the printer and waste paper whilst following this tutorial, simply create a new project, set the forms backcolor to white, autoredraw property to true, and remove change any Printer.Function to Function. You will also need to comment out the Printer.EndDoc lines. The data that was going to be printed on paper will now be 'printed' to the form instead.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only two kinds of languages: the ones people complain about and the ones nobody uses” - Bjarne Stroustrup