C#判断鼠标在某个区域内

1、判断鼠标是否在某个区域

Rectangle rectangle = new Rectangle(区域的坐标和大小);   if (rectangle.Contains(MousePosition))  {  }

这里要注意,区域的坐标是相对于屏幕还是相对于工作区域。

2、判断鼠标是否在某个控件上

Rectangle rectangle = 控件名称.RectangleToClient(this.ClientRectangle);  if (rectangle.Contains(MousePosition))  {  }



 

你可能感兴趣的:(工作,C#)