Make sure the button in a specific area

How to check that a button is in a certain area, I have two buttons, and the user is a rectangle drawn with a mouse. How to check if a button is in the rectangle to take action if it is set correctly?
This image from my Winform when creating a rectangle contains my buttons, I want to find the buttons located in the rectangle area, do an action This image from my Winform when make an rectangle contain my buttons, I want when find the buttons located in the rectangle area make an action

+4
source share
1 answer

Just use the Contains method as follows:

if (_yourSelectionRectangle.Contains(new Rectangle(button4.Location, button4.Size))
{
    ...
}
+2
source

All Articles