Search Amazon:

Display Window's Page Setup Dialog from VB.NET

From .NET you can display Windows standard Page Setup Dialog using the PageSetupDialog object. While this object derives from the System.Windows.Forms namespace you need to create a PrintDocument which derives from the System.Drawing.Printing namespace.

    Imports System.Drawing.Printing

    Private myDocumentToPrint As PrintDocument
    Private myPageAlreadySetUp As Boolean = False

The PrintDocument object is the key to printing in .NET. and is similar to VB6's Printer object. Click here to learn more about using the PrintDocument object.

The PageSetupDialog object lets you display the Page Setup Dialog and control which features, such as paper orientation, printer selection, etc., are available by setting the corresponding properties. However, these settings are only in effect for the PrintDocument you associate with your PageSetupDialog object.

    Dim psd As New PageSetupDialog

    With psd
        .AllowMargins = True
        .AllowOrientation = True
        .AllowPaper = True
        .AllowPrinter = True
        .ShowHelp = True
        .ShowNetwork = True

        .Document = myDocumentToPrint
    End With

After instantiating a PageSetupDialog object you can set its default values prior to showing the dialog. Typically you would do this before showing the dialog the first time. Subsequently you would just let the dialog display the current values.

    '
    ' Set defaults on initial display.
    '
    If Not myPageAlreadySetUp Then
        With psd.Document.DefaultPageSettings
            .Margins.Top = 50
            .Margins.Left = 50
            .Margins.Right = 50
            .Margins.Bottom = 50
            .Landscape = True
        End With
    End If
    '
    ' Show the Page Setup Dialog.
    '
    psd.ShowDialog()
Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2009 TheScarms