Allan L
Allan L

Reputation: 31

If Cursor is in Location

if (Cursor.Position == closeButton.Location)
{
    closeButton.BackColor = Color.FromArgb(255, 231, 76, 60);
}

This if statement doesn't work for some reason, any help?

I would like it to check if the Cursor position is in the Location set.

Upvotes: 1

Views: 73

Answers (1)

Salah Akbari
Salah Akbari

Reputation: 39946

You need to check for ClientRectangle property of your button. So this is the proper syntax to use:

if (closeButton.ClientRectangle.Contains(closeButton.PointToClient(Cursor.Position)))
{
    closeButton.BackColor = Color.FromArgb(255, 231, 76, 60);
}

Upvotes: 3

Related Questions