I am writing an app where I create my own Pushbuttons from a Canvas. I have three events MouseDown, MouseMove, and MouseUp. The picture of the button changes with each event. On the Mac the mouse move works great - you slide the mouse over the button and the picture changes. But when I run the same app in Windows the MouseMove does not do anything. MoveUp and MouseDown work fine, but not MouseMove.
What am I doing wrong? The code for the MouseMove is shown below.
[code] dim C as Picture
If txtStyle.Text=“Blue Button” Then
C = w_PrintO
elseif txtStyle.Text=“Blue Background” Then
C= b_PrintO
elseif txtStyle.Text=“Charcoal” Then
C= c_PrintO
elseif txtStyle.Text=“Apple” Then
C= a_PrintO
elseif txtStyle.Text=“Red” Then
C= r_PrintO
elseif txtStyle.Text=“Wedgewood” Then
C= d_PrintO
End If
dim p as Picture = new Picture(bPrint.Graphics.Width, bPrint.Graphics.Height, 32)
p.transparent = 1
p.Graphics.DrawPicture(C, 0, 0, bPrint.Graphics.Width, bPrint.Graphics.Height, 0, 0, C.Width, C.Height)
bPrint.backdrop = p[/code]
Is there something I have to do in order to make this work under Windows? Any help would be appreciated.
Thanks Tim for taking the time to help. Putting the refresh at the end of the method just made everything flicker, because it refreshes with each pixel that the mouse hits. So I guess that won’t work.
Thanks for the advice on the Select Case. I will change it.
does txtstyle.text change while the cursor is inside the canvas/button? If not, why not use Mouseenter instead of Mousemove? This wouldnt trigger that often and should reduce flicker therefore.
I am sorry, but I do not see anything in this code you posted using the position of the mouse cursor related to the buttons : absolutely no mention whatsoever of X and Y. Just as puzzling, how do you make txtStyle.text change according to the mouse position ? Unless you have code in each button MouseEnter and MouseExit, I cannot see how you do that…
As I read it, this code cannot work as described, would that be on Mac or Windows. Your issue is not that the MouseMove event does not work, it is the code that needs attention. MouseEnter and MouseExit in the buttons is the most promising way of doing it with a minimum of flicker. Maybe you already have that ?
The reason for the current flicker is that you update the canvas backdrop at very mouse move. Incidentally, it shows the event does fire.
I followed Ulrich’s suggestions above and it now works correctly, both Windows and Mac. No flicker and the button highlights when you run the mouse over it. I uploaded an example project file below if anyone wants to see how I was working on it.
It looks like from the comments above, I’m doing it all wrong. The thing is I need to use Elastic Window in my project and the buttons don’t size correctly under Cocoa on high resolution monitors, so I am making my own buttons. I’m using the Canvas control and loading pictures depending what background the customer chooses. There are 6 different styles, so the images of the buttons load as to which style the user choses. I am sure there is probably a better way, but this is what I came up with.
I will look at the Canvas button example that Norman suggested.
Thank you everyone for trying to help me. I really appreciate you spending the time to help.