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”
me.Visible=(false)
case “hover”
me.Visible=(true)
end select
When mouse enters, prop = “hover”
Canvas1.Refresh(true)
and when mouse exit, prop = “normal”
Canvas1.Refresh(true)
No matter what i try whenever it becomes invisible it wont ever reapear.
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>=canvas1.top and y<=canvas1.top+canvas1.height and canvas.visible=false then
canvas1.visible=true
/// put code here as if a mouse enter
end if
and don’t use CANVAS1.REFRESH
use CANVAS1.INVALIDATE instead
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.
[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.
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.
Okay, i finally got it working with the folowing code in the paint event.
If canv1 = True Then
canvas1.Backdrop=image
canvas1.doubleBuffer=true
End If
If canv1 = false Then
canvas1.Backdrop=image1
canvas1.DoubleBuffer=true
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
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.
Also, did you go through the ‘Introduction to Programming with Xojo’ .pdf. A lot of things are covered in there and it’s fun: https://www.xojo.com/learn/
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.