Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Hi All,

    Some years ago I wrote a small program in vb5 for work (engineering shop) that calculated and then printed the x,y co-ordinates for a number of holes on a PCD (circle).

    With the change to VBe 2008 I was able to dredge up examples and modify them enough (without really understanding them) to get the print function to work, as long as it only needed 1 page.

    I needed a 2 page printout (lots of holes) the other day but the program just printed the first page and considered itself finished.

    As I use VB only every now and then, I really don't have a handle on the up to date stuff.

    Could someone modify my code for me so that it correctly prints to a second page when needed please?

    Code:
        Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
            Dim prn As New Printing.PrintDocument
            ' Handle the page events
            AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
            ' Do the print (Printing handled by the print page handler)
            prn.Print()
            ' Remove the page handler
            RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
        End Sub
    
        Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
            Dim coord As String
    
            args.Graphics.DrawString("PCD Pattern Co-ordinates", New Font("Arial", 14, FontStyle.Regular), Brushes.Black, 10, 30)
    
            args.Graphics.DrawString("Number of Holes. = " & TextBox1.Text, New Font("Arial", 14, FontStyle.Regular), Brushes.Black, 10, 90)
            args.Graphics.DrawString("PCD = " & TextBox2.Text, New Font("Arial", 14, FontStyle.Regular), Brushes.Black, 10, 120)
            args.Graphics.DrawString("Offset Angle = " & TextBox3.Text, New Font("Arial", 14, FontStyle.Regular), Brushes.Black, 10, 150)
    
            args.Graphics.DrawString("Hole Co-ordinates", New Font("Arial", 14, FontStyle.Regular), Brushes.Black, 10, 210)
    
            For A = 0 To ListBox1.Items.Count - 1
                coord = ListBox1.Items(A)
                args.Graphics.DrawString(coord, New Font("Arial", 14, FontStyle.Regular), Brushes.Black, 10, 240 + A * 30)
    
            Next A
        End Sub
    "Heading for the deep end"

  2. #2
    New Lounger
    Join Date
    Apr 2010
    Location
    Colorado, USA
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What you're missing is setting args.HasMorePages = True (it's false by default).

    That tells your PrintDocument instance you have more pages you want to print, so it keeps calling your PrintPageHandler method.

    When you have printed all your pages, set args.HasMorePages = False.

    Now, given what it appears that the printing is doing, you will also have to add some logic to keep track of which lines you have printed so that you know where to start on each page and don't keep printing the same lines over and over.

    This usually entails determining the printable area of the page and determining the height of a printed line (based on the font).

    Then as you're printing lines you keep track of where you are down the page so that you know when you have a page full, and then keep record of where you stopped so you know which entry should be the first line on the next page and proceed from there.

    A quick Google search on something like "line printing in .net" should get you plenty of examples.

    HTH

    stephen posey

Posting Permissions

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