-1

I've made a WinForms application and I need to show a formatted document with text and images on the screen.

I've searched a lot of options, I've discarded reporting services and crystal reports because I only need one sheet and I don't want a report server.

Which could be the best option? The only thing that I need is to generate a document with text and images, then display on the screen the generated document and print it.

Thanks a lot.

sonne
  • 377
  • 5
  • 20
uoah
  • 169
  • 1
  • 4
  • 13
  • 2
    do you mean something like print preview? –  Jun 19 '13 at 18:40
  • yes, more or less, but I need to put the images and text in a template – uoah Jun 19 '13 at 18:52
  • PDF (you'll need a 3rd party library), or generate an image and send to print preview. Actually, HTML would probably be the easiest. – mbeckish Jun 19 '13 at 18:55
  • I've discarded PDF too because I need to show in the winforms screen without using a pdf client like adobe reader. Any good tutorial of the html solution? – uoah Jun 19 '13 at 19:01
  • @uoah - A tutorial for how to code HTML, how to write text (HTML) to a file, or how to have WinForms open a browser to display an HTML document that is stored on the local harddrive? – mbeckish Jun 19 '13 at 19:10
  • If you don't want to open an external browser, you can use the webbrowser control, and have it [open local content](http://stackoverflow.com/q/72103/21727). – mbeckish Jun 19 '13 at 19:13
  • the last one ;) I don't neet to display a stored document but I need generate on the fly and display inside my app. thanks! – uoah Jun 19 '13 at 19:14
  • I'm not sure if you will be able to stream content in memory to a browser, unless you set up your winforms app to be a mini web server. It would probably be easier to write it out to a local file. – mbeckish Jun 19 '13 at 19:16
  • If You want to display the data in the form in WinForms and then allow user to print it, You can just print the content of the window. You can find some sample code here: http://www.c-sharpcorner.com/uploadfile/srajlaxmi/printing-windows-form-in-C-Sharp-net/. It just renders the window as image and then prints it. – Lukasz M Jun 19 '13 at 19:47
  • Thanks Lukasz that was my last option but i have present. – uoah Jun 19 '13 at 20:35

1 Answers1

0

The bad news is that winforms is a useless dinosaur and doesn't support anything like that.

The good news is that .Net has a much better, newer and more capable UI framework called WPF, which does have a consistent Document Model that you can use to create all sorts of Documents (including WYSIWYG documents).

Some Samples of WPF FlowDocuments:

enter image description here

enter image description here

At this point you might think... So, What do I do? Do I just scrap my existing winforms app and start all over in current, relevant, non-useless non-dinosaur technologies? Well, that is always a great idea, but not always possible. Therefore my suggestion is that you leverage the ElementHost winforms control in order to integrate the WPF document capabilities into your existing winforms application

Federico Berasategui
  • 43,562
  • 11
  • 100
  • 154
  • Thanks but that I need to display and print is very simple, i don't need wpf but in a near future I will learn it and begin to migrate my winform app. – uoah Jun 19 '13 at 20:37
  • @uoah if you "don't need WPF" (which is something I can't really understand), then why don't you just use pure winforms' capabilities for this? – Federico Berasategui Jun 19 '13 at 20:43
  • My app is a winforms basic app that manages customers and n worksheets for every customer. All are basic listview with data and thats because I say don't need WPF. The basic problem was how to display the worksheet information to the user. – uoah Jun 19 '13 at 21:58
  • @uoah please read thru my answer again. You can use WPF only to do the relevant `Document` parts and leave the rest as it is. – Federico Berasategui Jun 19 '13 at 22:19
  • Yes I know, I used before WPF with elementHost inside winforms. Anyway I resolved with embedding an html navigator. – uoah Jun 20 '13 at 06:54
  • Anyway I will try WPF Flow document. Thanks – uoah Jun 20 '13 at 09:24