Silver Light 4.0 Feature No-1 Printing Support

No.of Views619
Bookmarked0 times
Downloads 
Votes0
By  Dhananjay Kumar   On  16 Feb 2010 00:02:57
Tag : Silver Light and XAML , Printing
Silver Light 4.0 Feature No-1 Printing Support
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Objective

This article will introduce New Printing support in Silver Light 4.0.

Introduction

Silver Light 4.0 add support to enable business application development. Printing support allows developer to print the Silver Light application itself. Printing support helps
1. Formatting the content of the Printing.
2. Specifying the content of the Printing.
3. Choosing the Printer.

How Printing support works?

While using the Printing support classes, eventually Silver Light application opens the Printing Dialog box like below.
 

Image Loading

 

What is new in Silver Light 4.0 for printing support?

Answer is PrintDocument class. This class provides events and function to achieve Printing in Silver Light application.

PrintDocument class

1. This class is inside namespace System.Windows.Printing.
2. There are three events to handles printing. They are EndPrint , StartPrint , PrintPage.
3. There is one method called Print() to do the print operation. This method takes no input parameter.
4. There is a property DocumentName .

How to use this class?
1. Create instance of PrintDocument class.
2. Specify the content to print.
3. Write code to handle the PagePrint event.
4. Entire SilverLight control can be printed by setting PageVisual to layout.
5. Portion of silverlight application can be printed by setting the pagevisual tospecific control.


Diving to some example
I have a

1. Stack Panel inside a Grid
2. Inside Stack Panel there is one button and a text box.

<Grid x:Name="LayoutRoot" Background="Azure"><StackPanel Height="auto" Width="auto" x:Name="stkPanel" Orientation="Horizontal" ><TextBlock x:Name="txtBlcok" Text="Dhananjay Kumar" Height="40" Width="175" /><Button x:Name="mybutton" Content="Print" Click="mybutton_Click" Height="30" Width="50" /></StackPanel> 
</Grid>

Now I need to, Print the text Box
1. Create instance of PrintDocument class.
2. Handling PrintPage event
3. Inside the event setting PageVisual to name of the text box.
4. Calling the Print() method in last.
5. If you want to print the entire application, just set PageVisual to any layout like stack or Grid. In this case for stack PageVisual would be set to stkPanel

private void mybutton_Click(object sender, RoutedEventArgs e)
{
    PrintDocument prt = new PrintDocument();
    prt.PrintPage +=(s,args) =>
        {
            args.PageVisual = txtBlcok;
        };
    prt.Print();
}
Image Loading

On clicking of Print Button, Here you could select you Print options. 

Image Loading

Conclusion

In this article, I gave a basic introduction of Printing Suppot in Silver Light 4.0. Thanks for reading.

 

 
Sign Up to vote for this article
 
About Author
 
Dhananjay Kumar
Occupation-Software Engineer
Company-Infosys Technolgies,Pune
Member Type-Gold
Location-India
Joined date-20 Jul 2009
Home Page-http://dhananjaykumar.net/
Blog Page-http://dhananjaykumar.net/
Dhananjay Kumar is Microsoft MVP on connected system. He blogs at http://dhananjaykumar.net/ . You can follow him http://twitter.com/debugmode_/ and reach him at dhananjay.25july@gmail.com
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top