Mouse clicks? (Window)

Hi,

I am creating an app that has a bug flying (it’s the square but moves at random speed) that changes colour whenever the mouse moves in or out of the window, I also have changed the window to do the same thing…except for the speed.

How do I change the -color from changing when the mouse exits and re-enters the window to when the mouse is clicked (left or right button) or when it is moved around in circles?

Thanks in advance.

You detect mouse clicks by putting code in a MouseDown event - either of the canvas if you’re using one, or the window. What have you tried?

I have tried both canvas and window, the keydown event and mousewheel (for canvas); I cannot remember the code I had in the canvas but the one I had in the window was

if( X < ((window1.Width/2)-(Me.Width/2))) or( X > ((window1.Width/2)+(Me.Width/2))) or (Y > Me.Height )then
me.backcolor = RGB (rnd250,rnd100,rnd*10)
end if

[quote=169734:@Walideh Sayed]I have tried both canvas and window, the keydown event and mousewheel (for canvas); I cannot remember the code I had in the canvas but the one I had in the window was

if( X < ((window1.Width/2)-(Me.Width/2))) or( X > ((window1.Width/2)+(Me.Width/2))) or (Y > Me.Height )then
me.backcolor = RGB (rnd250,rnd100,rnd*10)
end if[/quote]

Keydown is for the keyboard. What you want is MouseDown.

I meant keydown, my code is wrong and I do not know what the code is…do you know the right code to write in the mousedown event of the window?

You can detect when the mouse exists the window in MouseExit. And when it enters in MouseEnter. I cannot tell you what code you need without much details, but when you click, code happens in MouseDown. That is where you want to do whatever you want to do.

Detecting rotations of the cursor is a whole lot more complex, but the place where it can be done is MouseMove.

[quote=169751:@Michel Bujardet]You can detect when the mouse exists the window in MouseExit. And when it enters in MouseEnter. I cannot tell you what code you need without much details, but when you click, code happens in MouseDown. That is where you want to do whatever you want to do.

Detecting rotations of the cursor is a whole lot more complex, but the place where it can be done is MouseMove.[/quote]

Right now, I have:

  1. A square with two properties, one with an integer of xSpeed and the other with ySpeed and a default of 5, and -5. Then I have a timer (only one) with a code written in to have the square bouncing off of all four walls.
  2. In the event of MouseEnter, in the window, I have the following code(s):
    me.mousecursor = system.cursors.fingerpointer (is there another variable to write instead of fingerpointer?)
    me.backcolor = RGB (rnd250,rnd100,rnd10)
    pongball.fillColor = RGB (rnd
    500,rnd500,rnd500)

if me.backcolor = RGB (250,100,10) then
pongball.FillColor = RGB (250,100,10)
end if

(This changes the colors for the background and square randomly but the thing is it’s when the mouse exits and re-enters that the background changes but I’d like to have the background change with the click of the mouse or when it moves around.)

I added this to the coding in MouseDown event, but in a new window since I could not find the MouseDown event in the already open window which is weird…anyways this is the code:

If IsContextualClick Then
me.BackColor = RGB (rnd500,rnd500,rnd*500)
End if

it did not do anything…

You must call refresh or invalidate if you want it to redraw.

If IsContextualClick Then
   me.BackColor = RGB (rnd*500,rnd*500,rnd*500)
   me.Refresh
End if

[quote=169770:@Tim Hare]You must call refresh or invalidate if you want it to redraw.

If IsContextualClick Then me.BackColor = RGB (rnd*500,rnd*500,rnd*500) me.Refresh End if [/quote]
It worked! Thank you so very much :slight_smile:

Is there a way to do it for the right click, though?

That IS the right-click. Or am I missing something.

it works for my left, only…is there another word for contextual? or would it be something other than
me.refresh?

would it be
me.invalidate?

[quote=169785:@Walideh Sayed]would it be
me.invalidate?[/quote]

that just used the left click, so no…

Don’t know what to say. IsContextualClick means right-click. Your code shouldn’t fire on left click.

which code is for the left click, maybe my window is reading the code opposite of its meaning or something (if that is even a possibility)?

MouseDown fires on both left and right clicks. You distinguish between them by checking IsContextualClick.

oh, it is left on my window could it have been affected by another item on the window, perhaps another code?