How to Create a Print Preview Control in Visual Basic

Part 1 of 3:

The Form

  1. How to Create a Print Preview Control in Visual Basic Picture 1
    Adjust the form to the size you require.
    1. It doesn't matter what size the form is, providing it can fit a large textbox and two buttons.
  2. How to Create a Print Preview Control in Visual Basic Picture 2
    Add a RichTextBox to your form.
    1. You can add a RichTextBox by double-clicking or dragging it onto the form.
    2. Adjust the size of the RichTextBox to your requirements.
  3. How to Create a Print Preview Control in Visual Basic Picture 3
    Add two Buttons to your form.
    1. Ideally, place the two Buttons near the RichTextBox.
    2. Again, you can add Buttons to your form by double-clicking or dragging onto the form.
  4. How to Create a Print Preview Control in Visual Basic Picture 4
    Name the Buttons "Print" and "Print Preview".
    1. You can change the text for the buttons in the properties box.
  5. How to Create a Print Preview Control in Visual Basic Picture 5
    Add the controls: "Print Document" and "PrintPreviewDialog" to your form.
    1. These will not be visible on the form as they perform in the background.
  6. How to Create a Print Preview Control in Visual Basic Picture 6
    Click on PrintPreviewDialog and change the "Document" to "PrintDocument1".
    1. You can change this in the properties box after clicking on PrintPreviewDialog.
Part 2 of 3:

The Code

  1. How to Create a Print Preview Control in Visual Basic Picture 7
    Double-click on your "Print Preview" button.
    1. This will bring up the page for coding.
    2. A Private Sub has already been created and awaiting code to tell it what to do when the Print Preview button is clicked.
    3. Add the following code into the Private Sub: PrintPreviewDialog1.ShowDialog()
  2. How to Create a Print Preview Control in Visual Basic Picture 8
    Go back to the form and double-click on your "Print" button.
    1. You will be taken back to the page for coding.
    2. In the Private Sub that has been created, add the following code: PrintDocument1.Print()
  3. How to Create a Print Preview Control in Visual Basic Picture 9
    Go back to the form and double-click on "PrintDocument1" located underneath the form.
    1. You will be taken back to the page for coding.
    2. 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)
Part 3 of 3:

Debugging and Testing

  1. How to Create a Print Preview Control in Visual Basic Picture 10
    Click "Start" to begin the debugging and testing process.
    1. If you have followed part one and two of this article you should encounter no errors.
  2. How to Create a Print Preview Control in Visual Basic Picture 11
    Test to see if the Print Preview function works.
  3. How to Create a Print Preview Control in Visual Basic Picture 12
    Test to see if the Print function works.
  4. How to Create a Print Preview Control in Visual Basic Picture 13
    Clean up your code. 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.
3.9 ★ | 16 Vote

May be interested

  • Efficiently exploit printers in Windows Server 2003 (Part 3)Efficiently exploit printers in Windows Server 2003 (Part 3)
    in the previous article of this series, i have shown you the most effective way to manage a network printer is to create print queues on one of the network servers and force all print jobs to be go through that queue. in the second part of this series, we introduced some basic techniques for this
  • How to create a page printed vertically and print horizontally on a Word documentHow to create a page printed vertically and print horizontally on a Word document
    often when printing text, it will follow a horizontal or vertical print mode. so how to print alternately on word?
  • How to enable Windows Protected Print on Windows 11How to enable Windows Protected Print on Windows 11
    windows protected print windows 11 feature helps users better control the printing process, minimize the risk of vulnerabilities and protect sensitive information in printed content.
  • Create Label in Word 2010Create Label in Word 2010
    in the following tutorial, we will show you some basic and necessary steps to create and print label in microsoft word 2010 program with just a few steps to set up. technically, we can create labels directly with support tools right inside word, or save them as a separate file ...
  • How to Install and Setup Visual Studio Express 2013How to Install and Setup Visual Studio Express 2013
    visual studio express 2013 supports visual basic, c#, and c++. this makes it suitable for a beginner as the software is free to download and install. follow these simple steps below to install and setup visual studio express 2013. download...
  • Relax with 3 ways to print in this simple reverse orderRelax with 3 ways to print in this simple reverse order
    there is always a right way to print your documents. some inkjet printers print pages from the top, which means you have to manually reverse the print order. this is not a problem when printing only a few pages, but when you print a few hundred pages of documents then you need a trick to print them in reverse order so you can arrange them neatly.
  • PHP syntaxPHP syntax
    before starting programming in any language, the basic syntax and program structure is very important. this chapter introduces you to the basic php syntax, including: php tags, comments, print commands, echo commands, and two print and echo commands.
  • Flash CS4: Create Preview for Custom presetsFlash CS4: Create Preview for Custom presets
    in the previous lesson, you created a custom preset. however, your custom preset does not have a preview version yet and you see the preview not available text in the preview pane.
  • Why are there many Microsoft Visual C ++ Redistributable versions installed on the computer?Why are there many Microsoft Visual C ++ Redistributable versions installed on the computer?
    why are there many microsoft visual c ++ redistributable versions installed on the computer and what does that mean? let's tipsmake.com find out in this article offline!
  • Visual Studio Community - Download Visual Studio Community here.Visual Studio Community - Download Visual Studio Community here.
    visual studio community is a free, extensible, full-featured ide for creating modern applications for android, ios, windows, as well as web applications and cloud services.