2

I have a TextBox control in my Metro app and need to be able to simply print its contents. I have done my research ever since Windows 8 Dev Preview was around and I still cannot figure it out.

I've tried samples, read other answers and read the documentation - over, and over, and over. It just doesn't seem possible. So, after what, 2 years? I'm offering all my reputation (well, as much as they'll allow) in the hopes that someone can help me.

jay_t55
  • 11,362
  • 28
  • 103
  • 174
  • 2
    possible duplicate of [How to print the contents of a TextBox](http://stackoverflow.com/questions/15563886/how-to-print-the-contents-of-a-textbox) (I agree *that* question is not a duplicate, but I fail to see how *this one* is different from it.) – Cody Gray - on strike Mar 24 '13 at 12:08
  • Please note that the comment above is in relation to the original version of this question (even though it's not really a duplicate). This question has yet to be answered; anywhere. – jay_t55 Jul 27 '13 at 07:45
  • http://stackoverflow.com/a/15616372/1230188 doesn't work for you ? What are you facing the problem in that? – Farhan Ghumra Jul 27 '13 at 08:04
  • I just don't understand it is all. There's so much code involved and I can't seem to grasp even the general idea about printing a TextBox so even though I can print using the sample, and run the sample, I can't sort of merge it or rewrite/copy it to use in my app because the very moment I start to do so, I'm no longer able to print. – jay_t55 Jul 27 '13 at 08:10
  • 1
    I will upload the easiest sample or kind of library on GitHub as soon as possible. – Farhan Ghumra Jul 27 '13 at 08:18
  • 1
    Oooh thank you very much man. You are a very generous person. :) – jay_t55 Jul 27 '13 at 08:25
  • @Xyroid any chance you've uploaded the sample to Git? – jay_t55 Jul 30 '13 at 11:53
  • @Aeron it's on his original post (the one already pointed out as a possible duplicate) – Chris W. Jul 30 '13 at 20:57
  • @ChrisW., No it isn't, lol. On his other post he links to an old version (on Skydrive) which I couldn't get to work - that's not the one he's referring to in the comments here. – jay_t55 Jul 30 '13 at 21:19

1 Answers1

1

Here I have created a simple helper class which help you to print the Textbox content with its formatting. You just need to call static method of class Printer. The project on GitHub also contain test app.

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.)

You can add helper class via NuGet. If you want to enhance my existing helper class, fork on GitHub

Farhan Ghumra
  • 15,180
  • 6
  • 50
  • 115