-
I have a print preview routine that prints a report (I don't use a report writer) either to a PictureBox or the printer depending on the user's choice. When the report is printed on the printer and it is more than one page long, the page break is of course done automatically, but when printing to the PictureBox and I want the "pages" to match what is printed on the printer, I need to do the "page break" manually. I have a routine based on the PictureBox.CurrentY compared with the Printer.ScaleHeight that I thought worked all the time, but I just found out that it doesn't in some cases. Given that I only use one font size, can anyone come up with the code that will allow me to know when to "page break" my PictureBox?
-
I am having the same problem right now. I found the problem.
When comparing the font sizes between the PictureBox and the
Printer:
Printer.Font = PictureBox.Font
PictureBox.FontSize = 8
Printer.FontSize = 8
It is actually:
PictureBox.FontSize = 8.25
Printer.FontSize = 8.16
Thats why the pages dont match. I am trying to find a solution.
Ill let you know if i find anything.
-
Thanks for the update, I will very happy if you can solve the problem.
-
here is how i did it...
You want the position on the PictureBox to be the same as that
of the Printer. So, adjust the CurrentY of the PictureBox after a
print job:
Code:
Private Sub PrintText(Text as string)
PictureBox.Print Text
With PictureBox
Printer.FontBold = .FontBold
Printer.FontSize = .FontSize
.CurrentY = .CurrentY - (.TextHeight("") - Printer.TextHeight(""))
End With
End Sub
Thats it!
-
-
That is working fine for single printing lines. But, I have some
code that wrapps text if the line is too wide. The width of the
text on the PictureBox is also slightly different from the printer.
So, when enough text is typed, the accuracy falls. I have yet to
solve the horizontal typing problem.
-
Well, TextWidth is the companion to TextHeight.
-
I know that, my point is:
Picture.TextWidth("MyText") = 526
Printer.TextWidth("MyText") = 522
These are just junk values for demo.
When the fonts are equal for both PictureBox and Printer, the widths are off just a bit.