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?
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.
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:
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.
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 (rnd500,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