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.
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");
}
精彩评论