How to print an image in Picturebox control as its scale

  • Thread starter Thread starter CG3000
  • Start date Start date
C

CG3000

I have an Image in a picture box in VS 2005 that I want to print using
the following event handlers:

Private Sub btnPrintLabels_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Try
Me.PrntDoc_Img.PrinterSettings.PrinterName = "Canon MF3110"
Me.PrntDoc_Img.DocumentName = "Vitex Label"
AddHandler PrntDoc_Img.PrintPage, AddressOf Me.pd_PrintPage
PrntDoc_Img.Print()
Catch ex As Exception
MessageBox.Show("An error occurred while printing", _
ex.ToString())
End Try

End Sub
' Specifies what happens when the PrintPage event is raised.
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As
System.Drawing.Printing.PrintPageEventArgs)
' Draw a picture.
'ev.Graphics.
ev.Graphics.DrawImage(Me.PictureBox1.Image, _
ev.Graphics.VisibleClipBounds)

' Indicate that this is the last page to print.
ev.HasMorePages = False
End Sub

Problem is that is prints the image on a scale of "filling" the whole
81/.2 by 11 document
Not the scale of the image
How can I change that?

PrintPageEventArgs.Graphics class may be what I want but I dont konw
for sure.
Any ideas?
 
Instead of using the DrawImage(Image, Rectangle) overload, why not just
use the DrawImage(Image, Point) overload? Like this:

ev.Graphics.DrawImage(Me.PictureBox1.Image,
ev.Graphics.VisibleClipBounds.Location);

?
 
Thank you that worked. I will have to read up on what the difference is
between what you suggested and what I was using before other then
setting where the upper left corner will be.

Obviously that does something to set the scale of the image and the
bounds also.
 
If you specify a Rectangle, which is an upper-left corner, a width, and
a height, then DrawImage reshapes the image to fit the rectangle.

If you just specify a Point, then DrawImage assumes that you want the
image at its original size.
 
Back
Top