I've got a tabcontrol with multiple tab pages each containing a different picturebox
these pictureboxes have large images so the tab page is scrollable
when the tab page is selected, and the picturebox is displayed, a paint event triggers and e.graphics are drawn upon the picturebox image
now, when a print button is clicked, I am trying to resize the picturebox to fit page and print the full picturebox (the whole image, including the paint graphics and the non visible portion (scrollable))
The code below resizes and fits the picturebox (called picToPrint) to the actual page, and prints the image, but the e.graphics dont resize and dont print
I've tried printing via the PrintForm control from the VB PowerPack, but I only want to print the picturebox inside the tabpage, not the entire form
I would have to resize the graphics and repaint the resized image again before printing it
please advise
these pictureboxes have large images so the tab page is scrollable
when the tab page is selected, and the picturebox is displayed, a paint event triggers and e.graphics are drawn upon the picturebox image
now, when a print button is clicked, I am trying to resize the picturebox to fit page and print the full picturebox (the whole image, including the paint graphics and the non visible portion (scrollable))
The code below resizes and fits the picturebox (called picToPrint) to the actual page, and prints the image, but the e.graphics dont resize and dont print
VB.NET:
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
Dim ret As Windows.Forms.DialogResult
ret = PrintDialog1.ShowDialog()
If ret = Windows.Forms.DialogResult.OK Then
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
PrintDocument1.Print()
End If
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim siza As System.Drawing.Size
Dim Rctb As System.Drawing.Rectangle
Dim factorW As Single
Dim factorH As Single
Dim factor As Single
factorW = PrintDialog1.PrinterSettings.DefaultPageSettings.PrintableArea.Width / picToPrint.Size.Width
factorH = PrintDialog1.PrinterSettings.DefaultPageSettings.PrintableArea.Height / picToPrint.Size.Height
If factorH < factorW Then
factor = factorH
Else
factor = factorW
End If
siza.Height = picToPrint.Size.Height * factor
siza.Width = picToPrint.Size.Width * factor
e.Graphics.DrawImage(picToPrint.Image, 0, 0, siza.Width, siza.Height)
Rctb.X = picReference.Left * factor
Rctb.Y = picReference.Top * factor
Rctb.Width = picReference.Width * factor
Rctb.Height = picReference.Height * factor
e.Graphics.DrawImage(picReference.Image, Rctb)
End Sub
I've tried printing via the PrintForm control from the VB PowerPack, but I only want to print the picturebox inside the tabpage, not the entire form
VB.NET:
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
I would have to resize the graphics and repaint the resized image again before printing it
please advise