Handle the PictureBox.MouseMove event: the MouseEventArgs parameter will give you the location of the mouse pointer:
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
Point mouseIsAt = e.Location;
}
To actually check if this is on (or even in) your oval is harder:
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(new Rectangle(new Point(10, 10), new Size(100, 200)));
Region reg = new Region(gp);
if (reg.IsVisible(mouseIsAt))
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
"Hi sir.
That seems a nice and sharp answer, but I don't get something in code.
gp.AddEllipse(new Rectangle(new Point(10, 10), new Size(100, 200)));
What does this code actually do? Could you explain it a little for me?
My best regards..."
In order to test if a point is inside an ellipse, you can't just rely on the bounding rectangle - the corners are "missing" from the actual ellipse. And there is no way to get the actual points that the ellipse is made of: they don't really exist except when drawn!
The only way to do it is to set up a region which consists of the actual ellipse - which means setting up the ellipse as a GraphicsPath object first.
The example I gave creates a new Graphics path, and adds an ellipse to it: since I don't know how you are cretaing your oval, I couldn't refer to your code! However you are drawing the ellipse on your picture box, use the same code to add it to a GraphicsPath, and then create the Region from that - you will probably want this as a class level variable, rather than local, as well, but I illustrated it with local to keep the code together.