Results 1 to 9 of 9

Thread: If not all Text Printed then start new page

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    95

    If not all Text Printed then start new page

    Hello! I am developing an application and I want to utilize the print feature on it. I have got the printing down, full page, word wrap and stuff. Anyways, I wanna have it print to a new page if all words have not printed properly. Anyway? Like it detect it with New Rectangle for the word wrap? VB.NET, Thanks too!
    Code:
    Code:
        Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
            Dim font As New Font("Times New Roman", 12, FontStyle.Regular)
            'Possible new Solution!
            e.Graphics.DrawString(rtbVerticalText.Text & vbNewLine & "Incremented By: " & increment, font, Brushes.Black, New Rectangle(50, 60, 700, 800))
            e.HasMorePages = True
        End Sub
    Last edited by Dragnorian; Apr 26th, 2017 at 05:53 PM. Reason: Added Code

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: If not all Text Printed then start new page

    It's up to you to determine the size of the printable area on the page and how much text will fit inside that area. If there is more data to print then you set e.HasMorePages to True in the PrintPage event handler and the event will be raised again to print another page.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    95

    Re: If not all Text Printed then start new page

    Hello! So I tried the line of code that you stated. I put it in the print document area and almost printed 20 pages of the same code. Was the the wrong area?

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: If not all Text Printed then start new page

    It sounds to me like you used the right event, but haven't done anything in your code to increment position - so when page 2 is being printed, you are still starting with the data that belongs on page 1.

    Without knowing more about what you are doing it is hard to give advice, so I recommend posting your code for printing.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    95

    Re: If not all Text Printed then start new page

    Yes, it prints the exact same data. Here is what I want, I want to continue the data. Say I have 1000 numbers being printed. Only 800 fit onto page 1, I want then, the remaining 200, to be put on the second page and that is it. Here is my code:
    Code:
        Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
            Dim font As New Font("Times New Roman", 12, FontStyle.Regular)
            'Possible new Solution!
            e.Graphics.DrawString(rtbVerticalText.Text & vbNewLine & "Incremented By: " & increment, font, Brushes.Black, New Rectangle(50, 60, 700, 800))
            e.HasMorePages = True
        End Sub

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: If not all Text Printed then start new page

    Ah yes, your code is far too simple I'm afraid.

    Rather than just assuming that DrawString will automatically work out what to print for each page, you need to:
    • work out how much of the text can fit on to the page, and only print that.
    • keep track of how much you have printed, so you can change the position you start at for the next page (eg: if you printed 800 characters on page 1, start page 2 at character 801 of the text).
    • only set e.HasMorePages = True if you haven't reached the end of all the text


    (this is basically what jmcilhinney wrote above)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    95

    Re: If not all Text Printed then start new page

    See, I like that but here is the issue. I can't control how much numbers there are. There could be 2, 1000, hell, even 15,000 numbers. I am a new programmer hoping to learn by doing challenging projects and learning from the community. Like I can probably figure something out. But not in that way sadly. Do you have Skype or Discord to discuss this further than on the forums?

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: If not all Text Printed then start new page

    The first item in the list is the hardest, the others are probably things you could work out yourself once it is working.

    Unfortunately it has been a very long time since I needed to do that kind of thing, and don't have any code handy... I'd hoped that somebody else would post something, but as they haven't here are a couple of short threads I found in a search:
    http://www.vbforums.com/showthread.p...e-to-Wrap-Line
    http://www.vbforums.com/showthread.p...3-Text-Printer

    I can't test at the moment, but the things there look promising, especially in the first of those threads.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    95

    Re: If not all Text Printed then start new page

    Alright thank you!, I will check these links when I am not busy.

Tags for this Thread

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