Printing in VB.Net

  • Thread starter Thread starter balaji r via .NET 247
  • Start date Start date
B

balaji r via .NET 247

I am right now involved in a vb to vb.net migration. Can you help me in giving me hints/tips in converting statements like:
Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(strTmp) - LEFT_MARGIN - RIGHT_MARGIN) / 2) + LEFT_MARGIN

There are too many similar instances, where positions are calculated, where printing should happen. It will be of great help to me if anyone can throw some light on this. Thanks in advance. Awaiting an earliest response.
 
* balaji r via .NET 247 said:
I am right now involved in a vb to vb.net migration. Can you help me in giving me hints/tips in converting statements like:
Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(strTmp) - LEFT_MARGIN - RIGHT_MARGIN) / 2) + LEFT_MARGIN

There are too many similar instances, where positions are calculated, where printing should happen. It will be of great help to me if anyone can throw some light on this. Thanks in advance. Awaiting an earliest response.

In the 'PrintDocument''s 'PrintPage' event, you can use
'e.Graphics.DrawString' to draw a string at a certain position.
 
You will have to interop and call GetDeviceCaps to get the printer
offsets to make this work on a printer. ScaleWidth would be the difference
between the right hard margin and the left hard margin.
.NET printing works by doing DrawString at a location so just keep track
of the x location (and y location) in a variable(s) and draw as appropriate.
Note that the default measurement unit for a page is 1/100ths of an inch so
100.0,100.0 is at 1 inch from the top and left before taking hard margin
offsets.
The simplest thing for hard margins on the printer is to get them and
then do a Graphics.Translate by the negative amounts of these margins at the
start. I discover if I am drawing to a printer instead of a PrintPreview by
checking to see if the VisibleClipBounds of the page is smaller than the
page size.
If you need it I have some (C#) code that finds the printers hard
margins and I believe that Herfried has translated that to VB.NET as well.
My code does a lot of this type of printing and I just wrote a printing
library that takes does the drawstring at the correct location. I have
CtrShowAt, CtrShowBetween defined and just call them as the calculations
are all the same.

Ron Allen
balaji r via .NET 247 said:
I am right now involved in a vb to vb.net migration. Can you help me in
giving me hints/tips in converting statements like:
Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(strTmp) -
LEFT_MARGIN - RIGHT_MARGIN) / 2) + LEFT_MARGIN
There are too many similar instances, where positions are calculated,
where printing should happen. It will be of great help to me if anyone can
throw some light on this. Thanks in advance. Awaiting an earliest
response.
 
Back
Top