If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

The way to print has completely changed in .NET. It is a little more tricky.

The VB6 way of printing was from 20 years ago, in a time where printing was less sophisticated is today, when printouts looked more like old typewritten sheets than the multi-fonts, color and full of images documents when tend to print today. The Printer object was not sufficient for today's needs.

In .NET, Microsoft gave us a more complete control over the printer. Who says more complete means more complex.

You have 2 choices. Or you use a third party tool as stated in a previous post, which is what most programmers do. Or you take full control, but then have to work for it.

You use a PrintDocument (pd in the following code) to setup the printer:

The Print method does not do the job, it simply triggers the PrintPage event of the PrintDocument object. You write your actual printing code in this event.

What is tricky is that this event will be called once for each page, so you have to check on each call whether there are still pages to be printed. The ev parameter of the event is the object you use to get information about the printing environment. The ev.Graphics property lets you control what goes to the printer.

The following code prints all the strings in an array called lines. Printing in a loop from an array makes things simpler.

I sent you a straight copy of one of my methods to show you the concept. You will have to adjust it according to your own data. That is why I sent you the second piece of code which you might prefer to use.

The lines array is declared and filled outside of the method, so you do not see the declaration here. GetUpperBound enables me to know its size, since it change everytime I use the routine.

If you want to go the array route, it's declaration and initialisation in you case would be something like the following, where x is the number of lines minus 1: