views:

279

answers:

3

I'm developing an application in VB.Net (VS2008) which allows the creation of classroom layouts. The layout is a panel and has child panels (seat objects) the seats are then populated using drag and drop and show a preview of the person sitting there.

I would like to export this panel to a printable format such as jpeg, pdf etc.

I have tried using the CopyFromScreen but I can't get this to only output the layout panel. (some of the panel could be off the screen at the time of export)

I have also considered using HTML outputting each seat as an absolutely positioned div container. Then printing the HTML page.

What do people think is the best solution? And could you provide examples to back up your choice?

+1  A: 

You can use this (msdn) to draw the control to a bitmap:

dim bmp as new Bitmap(panel.Width, panel.Height)
panel.DrawToBitmap(bmp, panel.clientRectangle)

You can then save the bitmap using whatever format you choose.

Pondidum
This works fantastically. So simple! Thanks!
Banford
A: 

You talked about putting the contents of a Panel into an image.
If you use WPF, you can do a Print Preview. There was a question pertaining to this here on StackOverflow, just a day ago. It's pretty mechanical - any "visual" can be emitted to an XPS file then displayed in a DocumentViewer. The DocumentViewer control has a built-in print button that prints what is displayed. If you're using WinForms, this approach won't work.

Another approach is to just generate the image directly, and dynamically.
There are a number of articles out there that talk about dynamic image generation in ASPNET. Here's one. I understand that you don't use ASPNET, but the .NET code is mostly the same. You'd have to modify that code and produce your classroom layout by drawing on the Graphics object. Then, display that into your Panel, or print it.

Cheeso
Would like to move to WPF... but for this project 90% of it is already done. In winforms. Thanks anyway!
Banford