Print the Text in a Textbox Part II..(Page Setup and Print Dialog)
Submitted by janobe on Sunday, April 27, 2014 - 11:08.
This is the continuation of my previous tutorial which is the Print the Text in a Textbox. This time, I’m going to add the Page Setup and Print Dialog. In the Page Setup you can choose any setup that you wanted in your page and it contains selections such as the margin,sizes and etc.. While in the Print Dialog you can select the number of pages and copies that you want to print. And you can set up your printer too.
Let’s begin :
Open the file Print the Text in a Textbox and add the two Buttons, PageSetupDialog and Print Dialog in the Form. Name the two Buttons, first is “btnpageset” and the other one is “btnprintdia”. It will look like this.
Double click the “Page Setup” Button and do this following code.
After that, go to the design views, double click the “Print Dialog” Button and do this following code.
You can download the complete source code and run it on your computer.
![first form](https://www.sourcecodester.com/sites/default/files/firstform2.png)
- Private Sub btnpageset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpageset.Click
- With PageSetupDialog1
- 'SET THE VALUE THAT INDICATES THE PRINT DOCUMENT TO GET PAGE SETTING FORM.
- .Document = PrintDocument1
- 'SET THE VALUE THAT INDICATES TO MODIFY THE PAGE SETTINGS
- .PageSettings = PrintDocument1.DefaultPageSettings
- End With
- If PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
- 'SET THE DEFAULT SETTING FOR ALL THE PAGES TO BE PRINTED
- PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
- End If
- End Sub
- Private Sub btnpagedia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpagedia.Click
- If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then 'CHECKING THE DIALOG RESULT
- PrintDocument1.Print() 'START THE PRINTING PROCESS
- End If
- End Sub
Add new comment
- 164 views