Graphics in WebCanvas

Can I create graphics in a webcanvas in other than in the paint event?

Sure, you can always put your drawing code into methods. However, you’ll need to call them from within the Paint event.

Hallo Alex,
how can I do this ‘you’ll need to call them from within the Paint event’ ?
With Realbasic Pro I did it this way:… . But this seems not to work with a WebCanvas.
So, ist there another way to do this?

Paint event:

RunMyMethod(g as Graphics)



… but I just want to do this for example from the the MouseDown-Event to make changes on the graphic if the mousebutton is clicked over the canvas. IMHO: Your example is execute from start from the paint-event.

You might instead try drawing directly to your own Picture (that is a property of the web page). And then in the Canvas.Paint event handler, draw the picture.

Hi Paul, how can I do this?

Create a property of the page MyPic As Picture

Instantiate it in the shown event with the webCanvas dimensions

In your mouseDown event you draw to it. i.e.: MyPic.Graphics.Drawline(…)

In the WebCanvas Paint event you draw your picture in the graphics(g) property g.DrawPicture(MyPic, …)

The same as usual. Anywhere you want, just draw directly to an instantiated Picture property. It essentially acts as an off-screen buffer:

mPictureBuffer.ForeColor = &cff0000 mPictureBuffer.FillRect(0, 0, 50, 50)

Then in the Paint event handler, draw the buffer picture in the WebCanvas:

g.DrawPicture(mPictureBuffer, 0, 0)