Art W
Art W

Reputation: 2038

Get whats under the cursor

Is there a way to hook the mouse to detect what it's hovering over? Say I put my mouse over my uTorrent icon on the desktop. Is there a way to detect that and give me information pertaining to that icon/file ? Any help on this matter would be helpful. Thanks.

Upvotes: 3

Views: 386

Answers (1)

Daniel Lopez
Daniel Lopez

Reputation: 1798

There is probably no way to do it completely in managed code you might have to do some native code for it but I can give you the algorithm.

Lets say you know the location of the icon and the size then the alogrithm is simple.

Rectangle mouseBounds = new Rectangle(Cursor.Positon.X, Cursor.Positon.Y, Cursor.Width, Cursor.Height);

Rectangle iconBounds = new Rectangle(getIconX(), getIconY());
if (mouseBounds.Intersects(iconBounds))
{
   MessageBox.Show("Is hovering over icon");
}

Upvotes: 1

Related Questions