mardi 14 avril 2015

save print document or print preview as image in vb.net

I want to save print preview to an image file in vb.net . so far my application generate a print preview with the text user provides and it prints , but i want to save the printed image to my computer. I have already googled and saw lots of answer, like this http://ift.tt/1H3kfmc


But somehow its not working for me. Any help will be appreciate !!!


my current code


Public Class Form1



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PrintPreviewDialog1.ShowDialog()
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim fornt1 As New Font("Arial", 16, FontStyle.Regular)
Dim rect As Rectangle = New Rectangle(New Point(0, 0), PictureBox1.Image.Size)
e.Graphics.DrawImage(PictureBox1.Image, rect) 'Draw Image
e.Graphics.DrawString(RichTextBox1.Text, fornt1, Brushes.LightBlue, 500, 500)
End Sub


End Class


Aucun commentaire:

Enregistrer un commentaire