PrintDocument in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson describes the PrintDocument control


PrintDocument

This component represents an object that will be printed, and you use this object to send output to the printer.

When you use this object to print something, you create the object, set its properties (the printer's name, paper tray, etc.), and then call its Print method.

    ' start the document's printing process
    PrintDocument1.Print()


When PrintDocument needs to generate a page of output, it raises its PrintPage event. Your code catches that event, draws the page, and then sets the event handler's e.HasMorePages value to indicate whether that was the last page of output.

    Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) _
        Handles PrintDocument1.PrintPage
        ' Do something e.g. 
        e.Graphics.DrawString("test page #1", New Font("Arial", 12, FontStyle.Bold), _
 Brushes.Black, 10, 10)
        e.HasMorePages = False
    End Sub


Previous Lesson | Next Lesson


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.