VB.NET Technology

VB.Net Projects

VB.Net Project 1

Printing Controls
Previous Home Next
adplus-dvertising

These controls are used to take printing of documents whether in form of print screen or as printing in the content form . In following figure i tried to describe about these controls how you will use in your window application. For explaining this i had taken the previous example of dialog control, so lets proceed with printing controls.

Code for Print Preview- For performing this action first add namespace

Imports System.Drawing.Printing

Private PrintDoc1 As New PrintDocument()
Private PrintPreviewDialog1 As New PrintPreviewDialog()
Private Sub printToolStripMenuItem_Click(sender As Object, e As EventArgs)
	PrintPreviewDialog1.Document = PrintDoc1
	PrintDoc1.OriginAtMargins = True
	'To set or Get the Position of a Graphic Object
	PrintDoc1.PrintPage += PDoc_PrintPage
	PrintPreviewDialog1.ShowDialog()
End Sub

Create Method

Private Sub PDoc_PrintPage(ByVal sender As System.Object, 
	ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PDoc.PrintPage
        Dim bmp As New Bitmap(Me.Width, Me.Height)
        Me.DrawToBitmap(bmp, Me.ClientRectangle)
        Me.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
        'Takes the Snap of the Exact WindowForm size as Bitmap image
        e.Graphics.DrawImage(bmp, 0, 0)
    End Sub

Code for taking Print

Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, 
	ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
        PrintDoc1.Print()
    End Sub
Previous Home Next