Page 1 of 1

Determine "this canvas"

Posted: Tue Oct 10, 2017 5:55 pm
by [-hh]
If I have several objects of type Canvas, how can I determine which one to use for drawing the widget?

Re: Determine "this canvas"

Posted: Wed Oct 11, 2017 8:39 am
by LCMark
@hh: The only canvas which can be used to draw to the widget, is 'this canvas' as it is at the start of the OnPaint handler. The canvas provided there only exists for as long as the OnPaint handler runs - any other Canvas's are 'offscreen' canvas objects which can be used to produce images.

Re: Determine "this canvas"

Posted: Wed Oct 11, 2017 10:59 am
by [-hh]
Thanks.

I'm trying to write a basic Canvas cheat sheet and was looking for the reason why we have to write in OnPaint such often "this canvas" although there is only one.

Now I see the way to do complicated (and time consuming) but "static" parts of an OnPaint handler only once and then insert these, whenever needed, as pixel data of <otherCanvas>.

This is probably faster than to organize the layering of several widgets. And easier, especially if some of theses layers are native.