如果光标在位置
If Cursor is in Location
if (Cursor.Position == closeButton.Location)
{
closeButton.BackColor = Color.FromArgb(255, 231, 76, 60);
}
这个 if 语句由于某种原因不起作用,有什么帮助吗?
我想让它检查光标位置是否在位置集中。
您需要检查按钮的 ClientRectangle
属性。所以这是使用的正确语法:
if (closeButton.ClientRectangle.Contains(closeButton.PointToClient(Cursor.Position)))
{
closeButton.BackColor = Color.FromArgb(255, 231, 76, 60);
}
if (Cursor.Position == closeButton.Location)
{
closeButton.BackColor = Color.FromArgb(255, 231, 76, 60);
}
这个 if 语句由于某种原因不起作用,有什么帮助吗?
我想让它检查光标位置是否在位置集中。
您需要检查按钮的 ClientRectangle
属性。所以这是使用的正确语法:
if (closeButton.ClientRectangle.Contains(closeButton.PointToClient(Cursor.Position)))
{
closeButton.BackColor = Color.FromArgb(255, 231, 76, 60);
}