PrintDocument.Print Method (String)

Silverlight

Starts the printing process for the specified document by opening the print dialog box.

Namespace:  System.Windows.Printing
Assembly:  System.Windows (in System.Windows.dll)

'Declaration
Public Sub Print ( _
	documentName As String _
)

Parameters

documentName
Type: System.String
The name of the document to print.

ExceptionCondition
SecurityException

The print operation is not user-initiated.

In Silverlight 5 the printing defaults to vector printing. In Silverlight 4, the printing defaults to bitmap printing. You can specify bitmap printing in Silverlight 5 by using the PrintBitmap method.

Specify the output to print by handling the PrintPage event and by setting the PrintPageEventArgs.PageVisual property to the correct UIElement.

If the user cancels the print operation, the BeginPrint and EndPrint events will not occur.

The following code example shows a button event handler that calls the Print method and an event handler for the PrintPage event. In this example, an Image control, which contains a map, is printed.


Partial Public Class MainPage
    Inherits UserControl
    Private pd As PrintDocument()

    Public Sub New()
        InitializeComponent()
        pd = New PrintDocument()

    End Sub

    Private Sub PrintButton_Click(ByVal sender As Object, _
            ByVal e As RoutedEventArgs)
        pd.Print("M yMap")
    End Sub

    Private Sub pd_PrintPage(ByVal sender As Object, _
            ByVal e As PrintPageEventArgs) Handles pd.PrintPage
        e.PageVisual = mapImage
    End Sub
End Class



<StackPanel x:Name="LayoutRoot">
      <Button Margin="5" Width="200" Content="Click to print" x:Name="PrintButton" 
              Click="PrintButton_Click" />
      <Image Width="600"  Height="600" Source="RedmondMap.jpg" x:Name="mapImage"/>
  </StackPanel>


Silverlight

Supported in: 5, 4

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: