Hello I’m trying to use the classes. I would like to have a Canvas object with multiple variables and in the Paint event pass it my values … but it doesn’t work. If I use Canvas and write messagebox in Paint, when I open the project it works … if I do it using the created class it does nothing. Where am I wrong?
Insert_Class
name: CanvasEdited
Super:DesktopCanvas - select
NEXT:
on the CanvasEdited
Mouse Dx Key → Add Event Handler → Paint
Mouse Dx Key - > Create Event Definiton from Event
On Inspector i insert my values and edit name in PaintEdited
This is extremely dangerous… It leads to an infinite loop…
The MessageBox appears,
You click in OK
A Paint event is fired, and so the MessageBox appears…
@Emile_Schwarz OP is just trying to illustrate that their events aren’t firing as expected. Don’t get so caught up on trying to um-actually the OP that you miss the point.
@Federico_Giannetti in your CanvasEdited Paint event handler, do you raise your event definition at all? At some point in the CanvasEdited Paint event handler you will need to
RaiseEvent PaintEdited
You’ll then get the PaintEdited message box from Canvas1
use a paint event in the subclass canvas then it is for all instances
or
for the event where you place your own canvas object in the window, then you can create a individual method.
means if you add 2 paint events handlers, one in your sub classed canvas and one in the window canvas. one is not called. at least it was the behave of xojo in past.
Ok let’s say I managed to create the class and it works, the paint event is called when I open the Window and draw a rectangle on the canvas.
Now, if I wanted to call the class created by me PaintEdited from a Method and pass values to it, how do you do it? I can’t understand the mechanism.
In Button1 Pressed for examble something like that Canvas1.Pressed(12,12) to invoke the event associated with the canvas
you would store the data in properties then you call yourcanvasinwindow.refresh
and the paint event comes. (the older event method name was .invalidate)
inside the default paint event you can call a other method and forward “g”
something like
PaintBackground(g)
PaintGrid(g)
PaintObjects(g)
this methods would be placed in your subclassed canvas.
if you need to paint objects/shapes you would have a class with property selected true/false,
then you can highlight it in the paint event draw method.
if you need to select objects in your object list you would have a method with mouse x,y input,
it iterate over all objects, looks for intersection and set this selected flag.
Ok I can call the class with RaiseEvent PaintEdited(g,150,200) and update the PAINT event by calling Canvas1.refresh…then I can pass the values that interest me into the subclass … oh my what a struggle, for me it is all new Thanks for your patience.