Results 1 to 8 of 8

Thread: Print Preview in PictureBox Vs. Printing on Printer

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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?

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    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.
    Always looking for a better and faster way!

  3. #3

  4. #4
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    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!
    Always looking for a better and faster way!

  5. #5

  6. #6
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    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.
    Always looking for a better and faster way!

  7. #7

  8. #8
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    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.
    Always looking for a better and faster way!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width