How to Print in Vb.Net

Written by robert godard
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Print in Vb.Net
VB.net can be used to create forms on the computer (PhotoObjects.net/PhotoObjects.net/Getty Images)
<p>VB.net is a programming language developed by Microsoft and based on Visual Basic. It is programmed using software provided by Microsoft, which allows for VB.net components to be arranged and coded in a graphic interface. If you would like to have a document print ready, then you need to make sure to prepare it correctly, and provide the user with an option to print. You may also include a print preview dialogue box if you like.

Skill level:
Moderately Easy

Other People Are Reading

Instructions

  1. 1

    Open VB.net. Select "File" from the top menu, then "New" to create a new document. If you already have a document that you are working on, select "File" then "Open" and navigate to the current project.

  2. 2

    Select "Printing" from the left side of the screen. This will open up the printing options. Select "Print Document" and drag this component to the top of your document.

  3. 3

    Type the following code into the Print Document component:

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

         PrintDocument1.PrinterSettings.Copies = 1
    
         PrintDocument1.Print()
    

    End Sub

    You may change the number of copies if you wish, but everything else should stay the same.

  4. 4

    Select "Print PreviewDialog" from the "Printing" menu on the left side of the program to add a print preview function. Drag this component under the print document section and insert the following code:

    Private Sub btnPrintPreview_Click(ByVal sender As _

    System.Object, ByVal e As System.EventArgs) Handles _
    
    btnPrintPreview.Click
    
    dlgPrintPreview.Document = PreparePrintDocument()
    
    dlgPrintPreview.WindowState = FormWindowState.Maximized
    
    dlgPrintPreview.ShowDialog()
    

    End Sub

    This will attach the print preview to the print document component so that it displays the correct information.

  5. 5

    Select "File" from the top menu, then "Save" to save the document. The document is now ready to be printed.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.