Поделиться через


PrintForm.Print Method (Form, PrintForm.PrintOption)

Sends an image of a Windows Form to the destination specified by the PrintAction property, specifying the form and printing options

Namespace:  Microsoft.VisualBasic.PowerPacks.Printing
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Syntax

'Declaration
Public Sub Print ( _
    form As Form, _
    printOption As PrintForm..::..PrintOption _
)
public void Print(
    Form form,
    PrintForm..::..PrintOption printOption
)
public:
void Print(
    Form^ form, 
    PrintForm..::..PrintOption printOption
)
member Print : 
        form:Form * 
        printOption:PrintForm..::..PrintOption -> unit 
public function Print(
    form : Form, 
    printOption : PrintForm..::..PrintOption
)

Parameters

Remarks

The Print method prints all visible objects on a form. This includes any text or graphics drawn with Graphics methods.

If the form specified in the printForm parameter does not have focus, and the PrintOption parameter is set to either CompatibleModeClientAreaOnly or CompatibleModeFullWindow, an exception is raised. If PrintOption is set to ClientAreaOnly, FullWindow, or Scrollable, any form in your application may be specified, even if it does not have focus.

Note

When the PrintOption parameter is set to either CompatibleModeClientAreaOnly or CompatibleModeFullWindow, the form specified by the Form property must have focus. If it is not, an exception is raised. To avoid this, call the Focus method of the form before you call Print.

By default, only the client area of the form is printed. If you want to include the title bar, scroll bars, and border in the printed image, set the PrintOption parameter to either CompatibleModeFullWindow or FullWindow.

By default, only the currently visible part of the client area or form is printed. If a user has resized the form at run time, it will be printed as currently visible on screen. If, however, part of the form has been moved off the edge of the screen, the form will still be printed as if it were completely visible.

If you want to print the form at its designed size, set the PrintOption parameter to Scrollable.

The Print method uses one of two underlying implementations for printing. The implementation is determined by the PrintOption parameter. When this parameter is set to CompatibleModeClientAreaOnly or CompatibleModeFullWindow, an implementation that is backward compatible with the Visual Basic 6.0 PrintForm method is used. When this parameter is set to ClientAreaOnly, FullWindow or Scrollable, a different implementation that doesn't require the form to have focus is used.

Note

On some operating systems, text or graphics drawn with Graphics methods may not display correctly. In addition, if you set the PrintOption parameter to ClientAreaOnly, FullWindow or Scrollable, you may have to call the Refresh method of the form immediately after you call Print. If you do not call this method, artifacts might appear on the form.

Examples

The following example prints the current form to the system default printer, printing only the client area at its currently displayed size and using the non-compatible method of printing. This example requires that you have a PrintForm component named PrintForm1 on a form.

PrintForm1.PrintAction = Printing.PrintAction.PrintToPrinter
PrintForm1.Print(Me, ClientAreaOnly)
Me.Refresh

.NET Framework Security

See Also

Reference

PrintForm Class

Print Overload

Microsoft.VisualBasic.PowerPacks.Printing Namespace

Other Resources

PrintForm Component (Visual Basic)

How to: Print a Form by Using the PrintForm Component (Visual Basic)

How to: Print the Client Area of a Form (Visual Basic)

How to: Print Client and Non-Client Areas of a Form (Visual Basic)

How to: Print a Scrollable Form (Visual Basic)

Deploying Applications That Reference the PrintForm Component (Visual Basic)