Over a million developers have joined DZone.

A Helper Class to Print Text Box Content in a Windows Store App

DZone's Guide to

A Helper Class to Print Text Box Content in a Windows Store App

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.


Microsoft's documentationsample for printing is too complex. The sample app for printing shows only how to print RichTextBlock. There's no tutorial to print the TextBox content in a Windows Store app. Moreover, to print a single line string, one has to write too much code rather than a maximum of 10 lines in WinForm. So, this helper class provides the simplest method to print the text box content. It has only one static method. It prints the text box content with its formatting. It's majorly based on MSDN print sample.

I got the idea to write a library from the following Stack Overflow questions:

How to print the contents of a TextBox ? 

How do you print contents of a RichTextBox ? 

How do I print a TextFile OR contents of a TextBox in Metro apps ? 

How to use it ?

You have to call just one static method ShowPrintUIAsync of class Printer, it will do print job on your behalf.

await Printer.ShowPrintUIAsync(PrintPreview, MyTextBox, Guid.NewGuid().ToString());
  • PrintPreview is a canvas, which is mandatory to show print preview in device charm. You have to declare in your XAML. 
  • MyTextBox is a text box object, whose text content is going to be printed. 
  • Guid.NewGuid().ToString() is a file name for printing the document. (It will be applied if you are creating PDF or XPS file via printing.)
To install WinRT.TextboxPrintHelper as  NuGet package, run the following command in the  Package Manager Console.

I would be glad to have issues or suggestions from you, so I can improve this. If you want to fork the repository or post issues, find this helper class on GitHub .

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.


Published at DZone with permission of Farhan Ghumra. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}