Possible Duplicate:
Finding the overlapping area of two rectangles (in C#)
I have two areas identified by top left and bottom right corners (fig.1).
In c#, how can I test if they are in contact (fig.2)?

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Let’s say you have two
Rectangles which arer1andr2, you can check whether they intersects with each other by this:If you need the exact area which they intersects with each other, you can do this:
You can check the documentation:
Rectangle.IntersectsWith,Rectangle.IntersectAdditional important note:
I’ve just checked that if the two rectangles just touch each other on an edge,
Rectangle.Intersectreturns a rectangle with one dimension is zero , howeverRectangle.IntersectsWithwill returnfalse. So you need to note that.For example,
Rectangle.Intersecton{X=0,Y=0,Width=10,Height=10}and{X=10,Y=0,Width=10,Height=10}will return{X=10,Y=0,Width=0,Height=10}.If you hope to get
truealso if they just touch each other, change the condition to: