question

Les-0449 avatar image
0 Votes"
Les-0449 asked Les-0449 edited

printdoc1_printpage error

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


dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered Les-0449 edited

You wrote :

 AddHandler printdoc1.PrintPage, AddressOf Me.printdoc1_PrintPage

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




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Cast we meet again. Would you mind explaining it a bit more, I am trying to understand the way this works. What puzzles me I believe I used those 2 subs in 2 other parts of my program with no issues but it is quite possible that there must be a difference that I am just not seeing. What you said does in fact correct the issue just trying to fully understand it.

Thank you for taking the time to help me.

Les

ps When am I going to be able to help you with something <S>

oops I now see what you are saying Cast no need to explain I must be a bit tired its 3 am in NY thank you for your find

0 Votes 0 ·