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
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