Problems printing

W

William Cruz

This piece of code prints out a image that I have placed on a
picturebox. It currently prints it @ the top left hand side of the page.
I want to know how I can control where in the page this image gets
printed. Can anyone help? Thanks ;)

William


Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrint.Click
Me.Close()

'// insert code here to manage what to print //

'// insert code here to manage what to print //

' Declare the PrintDocument object.
PrintDialog1.Document = docToPrint


Dim result As DialogResult = PrintDialog1.ShowDialog()

' If the result is OK then print the document.
If (result = Windows.Forms.DialogResult.OK) Then
docToPrint.Print()
End If
End Sub
Private Sub docToPrint_PrintPage(ByVal sender As Object, ByVal e As
Printing.PrintPageEventArgs) Handles docToPrint.PrintPage

'e.Graphics.DrawString( text, printFont,
System.Drawing.Brushes.Black, 100, 100)

Dim mi As Reflection.MethodInfo = Form1.PictureBox1.GetType() _
.GetMethod("OnPaint", Reflection.BindingFlags.Instance Or _
Reflection.BindingFlags.NonPublic)

Dim text As String = "In document_PrintPage method."

Dim printFont As New System.Drawing.Font _
("Arial", 35, System.Drawing.FontStyle.Regular)

' Draw the content.
e.Graphics.DrawString(text, printFont,
System.Drawing.Brushes.Black, 0, 500)

mi.Invoke(Form1.PictureBox1, New Object() {New
PaintEventArgs(e.Graphics, New Rectangle(0, 0, 0, 0))})

End Sub
 
G

Guest

Why can't you just get the picture box image and use the drawimage method and
you can specify where to print on the page. You might have to play around
with the location with respect to the margins and the image resolution vs the
printer resolution to get the correct place on the page you want though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top