I’ve got a project going on and i want to draw a border around multiple canvas from clicking on one. Also, how do i call the paint event? I’ve read it’s canvas.refresh but it does not work.
Move the code, from your .Paint event, to a method and then you can call that method from the .Paint event, as well as from other methods…
Its canvas1.refresh or whatevernamethecanvashas.refresh
Canvas.refresh would call the class which obviously wont work.
Avoid using CANVAS1.REFRESH if at all possible… it can lead to over-use of the CPU if not done properly…
use CANVAS1.INVALIDATE instead… this allows the OS to schedule the exact refresh.
REFRESH does it “immediately” and without regard to other recent calls to REFRESH
INVALIDATE does it at the next CPU cycle that it can…
canvas1.refresh canvas1.refresh canvas1.refresh canvas1.refresh canvas1.refresh
will call the PAINT event FIVE times
canvas1.Invalidate canvas1.Invalidate canvas1.Invalidate canvas1.Invalidate canvas1.Invalidate
calls it ONCE
Detect event in mouse-down or other mouse events and
decide what to do with it.
is x and y in the given rectangle Example Rect1 = true
then draw in paint
if Rect1 = true then g.drawrect (left, top, width, height)
call canvas1.invalidate (false) in mouse-down
Thanks i’ll try it out!
I thought we were supposed to use .Invalidate instead of .Refresh
.Refresh does it right then and there
.Invalidate waits until the next screen refresh (or something like that)
[quote=386843:@shao sean]I thought we were supposed to use .Invalidate instead of .Refresh
.Refresh does it right then and there
.Invalidate waits until the next screen refresh (or something like that)[/quote]
Yup. Thats exactly what Dave said.
oh… I blocked Dave a while back, so don’t see his posts…
I just realized my 1st question wasn’t answered. Though i checked the xojo dev center and other resources again and it seems it has to be done manually. There’s no way to make a border appear around a canvas which I just clicked on with a premade function ? Is there a place on this forum or somewhere on the net that contains lots of functions made from people which everyone can use ? Like an online book containing encapsuled functions that can be used in whatever way we see fit for the project we make ? Finally, can i use g as graphics somewhere else than in the paint event ?
[quote=386729:@Louis Robitaille]Hey guys,
I’ve got a project going on and i want to draw a border around multiple canvas from clicking on one. Also, how do i call the paint event? I’ve read it’s canvas.refresh but it does not work.[/quote]
Just use Drawrect in the Paint event to draw the border in each canvas. Then when you do canvas.invalidate which will trigger the Paint event, and it will draw it.
the CANVAS control and the PICTURE object both have a graphics context
The CANVAS context cannot be accessed outside of the PAINT event, although you could forward if to another method
In some cases its best to draw into a picture and then have canvas display that picture… espeically if a large part of the display remains unchanged from cycle to cycle
[quote=387095:@Michel Bujardet]Just use Drawrect in the Paint event to draw the border in each canvas. Then when you do canvas.invalidate which will trigger the Paint event, and it will draw it.
This doesn’t seem to take the canvas having a backdrop into consideration. Is there a way to draw a transparent rectangle (borders only)?
confused… you can only draw within a graphics context
g.penWidth=50 g.drawrect 25,25,g.width-50,g.height-50
that draws a 50px wide border around whatever in inthe graphics context
[quote=387105:@Dave S]confused… you can only draw within a graphics context
I’m new to coding so could you explain to me what a graphic context is ? I searched it on the net and I don’t really get the definition most website are giving.
This will draw only the border. The rest will remain transparent.
in relation to a Canvas it is “g”
A canvas has more than just the drawing area. It has properties like left, right, name etc, it has events like open and paint, it has methods and all kinds of stuff. Now where the canvas can draw is the graphics context (or g for short) and also the backdrop (though try to avoid the backdrop).
Part of the confusion is that we associate picture with a photo, and Graphics with a drawing. But if graphics is the drawing then what do you call the area where you do the drawing? Canvas is already taken for the class name, picture is already taken for another class name, so the graphics is drawn in the graphics context.
Thanks for all you answers! I now understand those concepts.