First, you'll have to use the MouseMove event. There is no MouseOver event and the MouseHover event does not use MouseEventArgs, which you'll need. You can actually do it two different ways, one of which won't require you to save x,y and size.
1) If you *do* save x,y and s (size), then you can determine in the MouseMove event handler whether you're in the area like this:
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.X >= x && e.X <= x + s.Width && e.Y >= y && e.Y <= y + s.Height)
Console.WriteLine("Mouse At {0},{1}", e.X, e.Y);
}
You can also take care of the whole thing right in your DrawMyText() using anonymous delegates. By doing it this way, you won't even have to save x, y and s!!
private void TestDrawMyText(Graphics g, string MyText)
{
SizeF s = g.MeasureString(MyText, MyFont);
float x = this.Width / 2 - s.Width / 2;
float y = this.Height / 2 - s.Height / 2;
g.DrawString(MyText, MyFont, Brushes.Gold, x, y, StringFormat.GenericTypographic);
this.MouseMove += delegate(object sender, MouseEventArgs e)
{
if (e.X >= x && e.X <= x + s.Width && e.Y >= y && e.Y <= y + s.Height)
Console.WriteLine("Mouse in TextArea At {0},{1}", e.X, e.Y);
};
}
~~Bonnie
>>
>Hi Bonnie, I've tried saving the text position x + y values as fields in my class and checking them in the MouseOver event but no joy so far - I think the values are *very* accurate and unless the mouse coords are spot on it wont work - any ideas ? - thanks for your time :-)>>
>>You'd need to save both the x,y *and* the size ... that way you'd have a rectangle, centered on the x,y, of the area that the text is displayed in. Is that what you did?
>>
>>~~Bonnie
>
>Hi Bonnie, I didn't save the *size* only the xy coords, sorry if I'm being dumb here but how could I check whether the mouse is *in the area* having saved the size , thanks for your time