Canvas.DrawInto from a non visible canvas

Hello everyone,

I have a little problem: I have a PagePanel with some pages. In the first page, there is a canvas with some information I want to export to a png file. So, I’ve created this code in a button:

Dim pict As Picture
Dim f As FolderItem = GetSaveFolderItem(“image/png”,“Horario” + “.png”)
pict = New Picture(cvHorario.Width, cvHorario.Height, 32)

cvHorario.DrawInto pict.Graphics,0,0
pict.Save(f, Picture.SaveAsPNG)[/code]

which is working fine if the page selected is where the canvas is; but if another page is selected, the image created is blank.
How can I export the canvas to a file .png regardless the page selected in the PagePanel?

Thanks a lot!!

this is because a canvas is a non-persistant object as in it only fires the Paint Event when required, and the Paint event is only required when some or all of the Canvas is visible.

Perhaps reverse the process. Take what is in the Paint event, and draw it directly to the Picture, and then in the Paint event, simply “display that picture”

Thanks for your answer, Dave. In the Paint event there is nothing, actually. This canvas is like a container of some listboxes with data, so I don’t know how to implement your solution…

Then use .drawInto on the Listboxes to create your image and not the canvas.
BTW - If you want a container for your list boxes, why not use a ContainerControl which is intended for such use and not a canvas which is intended for drawing?

Hi Roger, thanks for your reply.

Yes indeed, I’ve tried .drawinto on the listboxes but with the same result: if the listboxes are on the screen, no problem; if they are on a different page, the image is blank.
On the matter of the container control, I use CC but I’ve read somewhere that this is not recommend to use a container control inside a PagePanel nor TabPanel. Actually, canvas in this situation is intended only for having the image from the listboxes in a easy way. So, it’s ok if I remove it if the purpose is not possible.