MouseMove Does Not Work In Windows


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.


Mac likes to draw a lot more than Windows does. Add a refresh to the end of the method and see if that helps.

Also getting the button text might look cleaner in a Select Case :slight_smile:

select case txtStyle.Text case "Blue Button" // blah blah blah case "Blue Background" // blah blah blah end select

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.

Use invalidate instead of refresh

Thanks Norman, but the MoveMove method still does not work and it still makes everything flicker quite a bit.


Perhaps you can add a label on the window somewhere and add this to your MouseMove Event to ensure its not working/working.

NewLabel.Text = "X: " + Str(X) + "   Y: " + Str(Y)

This will give you the X/Y coordinates which may help you.


Try this and see what happens… (untested, just general advice)

remove this line:

bPrint.backdrop = p

Assuming bPrint is a canvas, make p a property of the window instead of creating it every time in the mouse move

Do this in mouse move instead

p 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)

then in bPrint’s PAINT event, do this:

g.drawpicture p,0,0

Stick a break point in your mouse move event
I’m certain you will hit that

oh you’re using backdrop ……
yeah dont do that :stuck_out_tongue:
Have a peek in the Examples > Desktop > Custom Controls > CanvasButton which basically does what you want

Hi James,

does txtstyle.text change while the cursor is inside the canvas/button? If not, why not use Mouseenter instead of Mousemove? This wouldn‘t 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.

link text

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.

Glad to see your project is working, now.

Thank you Michel.
Thanks to you and all the other people that help me on this forum. :slight_smile: