15.12.10

Print Document with VB.NET

Hi Everybody,
I would like to explain one of faq within this essay , how can I can use printpreview and printerdialog with VB.NET 2010 windows application? If any question, please feel free and contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

1-) We are creating a new Windows Application Project (print_document)



2-) We are designing this windows form in a similar way to bellowing picture



3-)We are writing this code

Private Sub Print_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Print_btn.Click
printDocument1.Print()
End Sub

Private Sub Print_preview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Print_preview.Click
printPreviewDialog1.Document = printDocument1
printPreviewDialog1.ShowDialog()
End Sub

Private Sub printDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printDocument1.PrintPage
Dim fnt_t As Font
fnt_t = TextBox1.Font
e.Graphics.DrawString(TextBox1.Text, fnt_t, New SolidBrush(Color.Black), 10, 10)


End Sub


Private Sub fnt_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fnt_btn.Click
Dim font_dialog As New FontDialog
If font_dialog.ShowDialog() = DialogResult.OK Then
TextBox1.Font = font_dialog.Font
End If
End Sub

4-) Lets start application and change font




5-) Click Printpreview button




Have a great day

Yener Turkeli
yenerturkeli@v-basic.net

No comments:

Post a Comment