Share via

printdoc1_printpage error

Les 286 Reputation points
2021-09-17T23:20:41.317+00:00

I have used this routine in 2 other places successfully but when I try to use it in form3 I am getting the following error message

BC30456 printdoc1_printpage is not a member of Form3. I added the Print Document1 control on my form3 and have added Imports System.Drawing.Printing on top of my code in form3. Following are the 2 subs I use along with the error squiggly line under Me.printdoc1_PrintPage

    Private img As Image
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'prints whatever is on the blackboard
        img = Me.PictureBox1.Image
        Dim printdoc1 As PrintDocument = New PrintDocument
        AddHandler printdoc1.PrintPage, AddressOf Me.printdoc1_PrintPage
        Dim previewdlg As PrintPreviewDialog = New PrintPreviewDialog
        previewdlg.Document = printdoc1
        previewdlg.ShowDialog()
    End Sub
    Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim pageBounds As Rectangle = e.PageBounds
        Dim nFactor As Single = CSng(pageBounds.Width / img.Width)
        Dim nNewHeight = img.Height * nFactor
        pageBounds.Height = CInt(nNewHeight)
        e.Graphics.DrawImage(img, New Rectangle(New Point(), pageBounds.Size), New Rectangle(New Point(), img.Size), GraphicsUnit.Pixel)
    End Sub

On form3 I have panel1 and inside of panel1 I have picturebox1 and this is where my image is. Just trying to give you oas much info I can provide to help you.

Thanks in advance

Les

Developer technologies | VB
0 comments No comments

Answer accepted by question author

Castorix31 91,876 Reputation points
2021-09-18T06:59:54.367+00:00

You wrote :

AddHandler printdoc1.PrintPage, AddressOf Me.printdoc1_PrintPage

but you called the sub :
PrintDocument1_PrintPage (with Handles PrintDocument1.PrintPage)
instead of
printdoc1_PrintPage

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.