Mouse enter, to change canvas Color

Hi there, im Rick and im new here.
I am trying to make a menu for windows.
I want to change the color of a canvas when mouse enter by having a copy of the canvas over the other one with slightly different color.
I want to invisible until mous enters, this is what i got.

select case prop
case “normal”
case “hover”
end select

When mouse enters, prop = “hover”
and when mouse exit, prop = “normal”

No matter what i try whenever it becomes invisible it wont ever reapear.

thanks for helping me out.

with regards, Rick

I think if Canvas is invisible it don’t receive mouseenter event
May be put a textlabel over the Canvas with same Canvas’s size
Then, use textlabel events to rendre or n’ont Canvas.
You have to place textlabel on front

or in MouseMove of the window or container hosting the canvas.

if x>=canvas1.left and x<=canvas1.left+canvas1.width and y> and y< and canvas.visible=false then 
/// put code here as if a mouse enter 
end if

and don’t use CANVAS1.REFRESH

Rick, I think you make things difficult if you flip around visible or putting a copy of a canvas over it etc.
Why not enable/disable a boolean on .MouseEnter/.MouseExit and change color in the paint event.

Like this:

[quote=262164:@Marco Hof]Rick, I think you make things difficult if you flip around visible or putting a copy of a canvas over it etc.
Why not enable/disable a boolean on .MouseEnter/.MouseExit and change color in the paint event.

Like this:[/quote]

Hi Marco,

Thanks all for your effort in helping me.
I dont have it quite yet though, Im using your method now, only thing i do now is change the backdrop in the paint event.
with me.backdrop=image. when mouseove=true it should change the backdrop, somehow it only flickers when mouseover=true.

Hi guys,

Okay, i finally got it working with the folowing code in the paint event.

If canv1 = True Then

End If

If canv1 = false Then
End If

it is not flickering anymore and works just fine!
Only problem is when i want to do this with the next canvas the first will stop working :frowning:
i created another boolean properties and did exactly the same. It somehow only works with one.

On Windows, turn off EraseBackground and switch on DoubleBuffer on every Canvas to avoid flicker. Maybe it’s better to set it in the inspector (on the right) instead of in code (and in your code above, .DoubleBuffer is enabled after your code ran for the first time)

Initially, you said you wanted to change color. If you want to change the backdrop image it’s a bit different. There are two ways:

  • The first is setting (and removing) a backdrop image. Pretty much what you tried above.
    For this, you don’t need the .Paint event or booleans. Just set the image in the .MouseEnter. And remove (Nil) it in the .MouseExit. Don’t forget to tell the Canvas to redraw itself (because you’ve changed something). You do this with .Invalidate.

  • The second way is drawing the image yourself. I prefer this because you have much more control over things. This way you can change size, position and even color.

See both examples here:

Also, did you go through the ‘Introduction to Programming with Xojo’ .pdf. A lot of things are covered in there and it’s fun:

IMPORTANT, about double buffer : it does not support transparency. So the transparent parts of a picture will show with the same color as the window. If you need transparency, do not use DoubleBuffer. EraseBackground False may suffice to reduce flicker.

And in Windows as well as Mac, if you have anything in Paint, NEVER place a control over the canvas. It would flicker crazy. Better use a backdrop picture if you want to have a control over.