Get what's under the cursor

Is there a way to plug in a mouse to determine if it is hovering? Let's say I hover over the uTorrent icon on the desktop. Is there any way to detect this and provide me with information related to this icon / file? Any help on this would be helpful. Thank.

+3
source share
1 answer

There is probably no way to do this completely in managed code, you may have to make your own code for it, but I can give you an algorithm.

Suppose you know the location of the icon and the size, then the algorithm 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");
}
+1
source

Source: https://habr.com/ru/post/1743419/


All Articles