re-using the Paint event

I have a window that I am using as a blank form to write graphics to (i.e.; draw text and intrinsic primitives ).I don’t want to hard code the paint event to do just one task, so my question is; How do I reuse the paint event on a window? Or to put it another way. how to I manipulate and refer the paint event from a method?

I don’t understand what you mean by “blank form to write graphics to”. Is this something the user sees or is it to draw and save graphics offscreen or maybe something else?

All you can do is trigger the Paint event by calling Canvas1.Invalidate (or Canvas1.Refresh). If you want to actually call Paint with your own Graphics object you’ll need to move your drawing code to a method, which is callable.

[code]Sub Paint(g As Graphics, areas() As Realbasic.Rect) //event
End Sub

Sub theRealPaint(g As Graphics) //method
//drawing routine
End Sub

Sub Action() //some other code
dim p As new Picture(400, 400)
dim g As Graphics = p.Graphics
//save p
End Sub[/code]

To make it simpler the areas() parameter isn’t passed along.

You can use a switch

[code]Property drawType As integer = 0

Sub theRealPaint(g As Graphics)
Select Case drawType //switch which method to use
Case 0
Case 1
Case 2
End Sub

Sub drawIntro(g As Graphics) //actual routines
End Sub

Sub drawCard(g As Graphics)
End Sub

Sub drawResults(g As Graphics)
End Sub

Sub Action() //button to change drawing
drawType = 2 //set the drawing type
Canvas1.Invalidate //redraw
End Sub[/code]

An Enumeration might make a better switching variable. You could also use an array of delegates or many other ways.

Or instead of actually drawing in Paint it can just draw a Picture property. Then you just have to set or manipulate the Picture and call Invalidate. Whatever the Picture is gets drawn. This alleviates having to switch amongst all your drawing routines. You might even be able to use the Backdrop Picture so no extra property is needed.