Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Print Method (String)
Collapse the table of content
Expand the table of content

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)

public void Print(
	string documentName
)

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.


public partial class MainPage : UserControl
{
    PrintDocument pd; 

    public MainPage()
    {
        InitializeComponent();
        pd = new PrintDocument();
        pd.PrintPage += new EventHandler<PrintPageEventArgs>(pd_PrintPage);

    }

    private void PrintButton_Click(object sender, RoutedEventArgs e)
    {
      pd.Print("My Map");
    }

    void pd_PrintPage(object sender, PrintPageEventArgs e)
    {
        e.PageVisual = mapImage;
    }
}



<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:
© 2015 Microsoft