Hi guys,
I'm trying to work out how I can tell if a user places their mouse pointer over the area of a circle I have on a form. I want to rotate the circle depending on where the user places the mouse.
I know about the 'MouseMove' event & I've been able to track fine if the mouse is moved over a square, as this is pretty simple. However, I can't work out how to do it for a circle!
The way I'd thought to do it was simply to work out the circle's centre location & then anything that was the length of the circle's radius away, I thought would be in the circle. However the ways I've tried of doing this are clearly wrong as they just track if the mouse is over a virtual square whose length is the diameter of the circle - & so return that the mouse is over the circle, when it isn't as the circle obviously doesn't completely fill the square.
I wondered if anyone knew of a way to do this or even if there were a standard command for just such a thing?
I know the basics of working out what a circle's circumference is from its radius or diameter & I know how to work out a circle's area from its radius also. However, I've no idea how to track exactly a given sized circle's area over a form by X & Y location.
Thanks very much indeed,
Dan.
VulpesPosted Mar 10, 2011, 2:49 PM
DanPosted Mar 11, 2011, 3:11 PM
Hi guys,
Thank you very much indeed for all the replies. I really appreciate it : )
I used the solution from Vulpes, which worked perfectly in solving the problem : ) Thank you : )
So, just to clarify a bit more & explain exactly what is that I was doing wrong, so that people possibly reading this in the future might be helped by it…
Something that you can do is to manipulate the use of the 'MouseMove' event so that code is executed if a mouse pointer hovers over a particular part of your form (so that no clicking is required, just the mouse being moved). So, this was bit done & there were no problems with it.
The problem was that I hadn't been able to work out how to tell if the mouse was over a circle I have on my form.
The way I'd thought to do it was simply to work out the circle's centre location & then anything that was the length of the circle's radius away, I thought would be in the circle's area. This was correct but my maths was wrong.
I used x & y locations on the form, which was correct. However, I thought if anything was within the top, bottom & two sides of my circle, it would be within my circle. This was the bit that wrong! This calculation instead marked out a virtual square around the circle, which was the size of the circle's diameter.
I'm sure this is very obvious to those among you who understand the maths well but unfortunately I didn't & this is where the problem lay : )
Thank you very much once again,
Dan : )
Sam HobbsPosted Mar 10, 2011, 1:33 PM
Also you say that the "mouse is over a virtual square". Perhaps the solution is to figure out why that is happening and if so I think there is not enough information to help with that. That however might not be relevant, based on the clarification of the first point.
Raja KrishnamurthyPosted Mar 10, 2011, 1:30 PM
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.shape.mousedown%28v=VS.90%29.aspx
I think you need Shape.MouseMove event.
HTH.
Happy Programming!!!
Regards,
Raja