• We just launched and are currently in beta. Join us as we build and grow the community.

Print the Text in a Textbox Part II..(Page Setup and Print Dialog)

xklaa

Web Service Tester
X Rep
0
0
0
Rep
0
X Vouches
0
0
0
Vouches
0
Posts
52
Likes
17
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 500 XP
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.

firstform2.png


Double click the “Page Setup” Button and do this following code.

  1. Private

    Sub

    btnpageset_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    btnpageset.

    Click
  2. With

    PageSetupDialog1
  3. 'SET THE VALUE THAT INDICATES THE PRINT DOCUMENT TO GET PAGE SETTING FORM.
  4. .

    Document

    =

    PrintDocument1
  5. 'SET THE VALUE THAT INDICATES TO MODIFY THE PAGE SETTINGS
  6. .

    PageSettings

    =

    PrintDocument1.

    DefaultPageSettings
  7. End

    With
  8. If

    PageSetupDialog1.

    ShowDialog

    =

    Windows.

    Forms

    .

    DialogResult

    .

    OK

    Then
  9. 'SET THE DEFAULT SETTING FOR ALL THE PAGES TO BE PRINTED
  10. PrintDocument1.

    DefaultPageSettings

    =

    PageSetupDialog1.

    PageSettings
  11. End

    If
  12. End

    Sub

After that, go to the design views, double click the “Print Dialog” Button and do this following code.

  1. Private

    Sub

    btnpagedia_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    btnpagedia.

    Click
  2. If

    PrintDialog1.

    ShowDialog

    =

    Windows.

    Forms

    .

    DialogResult

    .

    OK

    Then

    'CHECKING THE DIALOG RESULT
  3. PrintDocument1.

    Print

    (

    )

    'START THE PRINTING PROCESS
  4. End

    If
  5. End

    Sub

You can download the complete source code and run it on your computer.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

451,993

323,299

323,308

Top