Adding a Print Function

function OpenWin(url, w, h) { if(!w) w = 400; if(!h) h = 300; window.open(url, "_new", "width=" + w + ",height=" + h + ",menubar=no,toobar=no,scrollbars=yes", true); } function Print() { window.focus(); if(window.print) { window.print(); window.setTimeout('window.close();',5000); } }
Team-Fly    

Special Edition Using Microsoft® Visual Basic® .NET
By Brian Siler, Jeff Spotts
Table of Contents
Chapter 15.  Multiple Document Interface (MDI) Applications


When you created the child form template, you included a PrintDocument control to allow for printing functionality. Some simple code will activate this feature. You can learn more about the PrintDocument control and printing in general in Chapter 23, "Creating and Using Reports."

Coding the Print Menu Command

Open the Code window for frmChild, and then open the Click event handler for the mnuFilePrint menu item. Add the code PrintDocument1.Print() to the procedure; this will cause the PrintDocument control to begin the printing process when mnuFilePrint is clicked. Your event handler should look like the following:

 Private Sub mnuFilePrint_Click(ByVal sender As Object, _      ByVal e As System.EventArgs) Handles mnuFilePrint.Click      PrintDocument1.Print()  End Sub 

Coding the PrintDocument Control

A single lineof code in the PrintDocument control's PrintPage event handler (which occurs when the control's Print method is invoked) will take care of printing the contents of the txtMain text box to the printer. Enter the following PrintPage event handler for PrintDocument1:

 Private Sub PrintDocument1_PrintPage(ByVal sender As Object, _      ByVal e As System.Drawing.Printing.PrintPageEventArgs) _      Handles PrintDocument1.PrintPage      e.Graphics.DrawString(txtMain.Text, New Font("Courier New", _          10, FontStyle.Regular), Brushes.Black, 0, 0)  End Sub 

    Team-Fly    
    Top
     



    Special Edition Using Visual Basic. NET
    Special Edition Using Visual Basic.NET
    ISBN: 078972572X
    EAN: 2147483647
    Year: 2001
    Pages: 198

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net