PDF download Download Article PDF download Download Article

Creating a Windows Application and need to know how to create a print and print preview control? Follow these simple steps and you will easily be able to print and print preview documents in your application.

Part 1
Part 1 of 3:

The Form

PDF download Download Article
    • It doesn't matter what size the form is, providing it can fit a large textbox and two buttons.
    • You can add a RichTextBox by double-clicking or dragging it onto the form.
    • Adjust the size of the RichTextBox to your requirements.
    Advertisement
    • Ideally, place the two Buttons near the RichTextBox.
    • Again, you can add Buttons to your form by double-clicking or dragging onto the form.
    • You can change the text for the buttons in the properties box.
  1. "Print Document" and "PrintPreviewDialog" to your form.
    • These will not be visible on the form as they perform in the background.
    • You can change this in the properties box after clicking on PrintPreviewDialog.
  2. Advertisement
Part 2
Part 2 of 3:

The Code

PDF download Download Article
    • This will bring up the page for coding.
    • A Private Sub has already been created and awaiting code to tell it what to do when the Print Preview button is clicked.
    • Add the following code into the Private Sub: PrintPreviewDialog1.ShowDialog()
    • You will be taken back to the page for coding.
    • In the Private Sub that has been created, add the following code: PrintDocument1.Print()
    • You will be taken back to the page for coding.
    • A Private Sub will be created called "PrintDocument1_PrintPage". Place the following code into the Sub: Dim font1 As New Font("arial", 16, FontStyle.Regular) e.Graphics.DrawString(RichTextBox1.Text, font1, Brushes.Black, 100, 100)
  1. Advertisement
Part 3
Part 3 of 3:

Debugging and Testing

PDF download Download Article
    • If you have followed part one and two of this article you should encounter no errors.
  1. After the debugging and testing process has completed with no critical errors, be sure to clean up your code. Make it look tidy and professional.
  2. Advertisement


Community Q&A

Search
Add New Question
  • Question
    How do I verify my username and password from a database using SQL Server?
    Md Mahadi Hasan
    Community Answer
    Open Microsoft SQL Server Management Studio. Connect to SQL Server as the 'SA' or an administrative user. Right-click on the Security folder > New > Login. Type in a login name. Check the bullet for SQL Server Authentication and type in a password. Click 'User Mapping' at the top left under 'Select a Page'. Check the database(s) to apply the user to, and type in the username for 'Default Schema'.
  • Question
    How come when I copy this, it says that "e" is an error?
    Community Answer
    You have probably placed it inside another sub. You need to paste it inside the Public Class.
Ask a Question
      Advertisement

      Video

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      Warnings

      • When coding, it is easy to misspell something. This can cause your whole application to fail.
      Advertisement

      About This Article

      Thanks to all authors for creating a page that has been read 110,187 times.

      Is this article up to date?

      Advertisement