Click to Rate and Give Feedback
MSDN
MSDN Library
Collapse All/Expand All Collapse All
Other versions are also available for the following:
.NET Framework Class Library for Silverlight
PrintDocument..::.PrintPage Event

Occurs when each page is printing.

Namespace:  System.Windows.Printing
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public Event PrintPage As EventHandler(Of PrintPageEventArgs)
C#
public event EventHandler<PrintPageEventArgs> PrintPage

Handle this event to specify the contents of the printed page. You can print the entire Silverlight control by setting the PrintPageEventArgs..::.PageVisual property to the layout root of the Silverlight content. Alternatively, you can print a portion of the Silverlight control by setting PrintPageEventArgs..::.PageVisual to the named UIElement that you want to print.

After the PrintPage event occurs, the specified PrintPageEventArgs..::.PageVisual will be sent to the printer to be printed. If the content is too large to fit in the PrintableArea, it will be clipped. If the HasMorePages property is true, the PrintPage event occurs again.

For more information about handling events, see Events Overview for Silverlight.

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.

Visual Basic
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
C#
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;
    }
}
XAML
<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.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker