tags:

views:

30

answers:

1

I have two rectangles InnerRectangle and OuterRectangle. I want to verify if four corners of InnerRectangle i.e, Lett, Top, Right, Bottom are completely inside of OuterRectangle. If those are outside I want change the ones that are outside. If I change Left/Top/Right/Bottom, how much should I change the width or height? Please let me know how to implement this.

if (InnerRectangle.Left < OuterRectangle.Left)
{
    // what should I put here
}
if (InnerRectangle.Top < OuterRectangle.Top)
{
    // what should I put here
}
if (InnerRectangle.Right < OuterRectangle.Right)
{
    // what should I put here
}
if (InnerRectangle.Bottom < OuterRectangle.Bottom)
{
    // what should I put here
}

Appreciate your help..

+1  A: 

To check whether rectangle InnerRectangle is completely contained inside OuterRectangle:

if (OuterRectangle.Contains(InnerRectangle))
{
    // ...
}

To fix InnerRectangle so that it is really inside OuterRectangle:

InnerRectangle = InnerRectangle.Intersect(OuterRectangle);
Timwi
Thanks, I don't want to replace the entire rectangle, just want to change the only corner(s) that is outside. Will this work?
Vin
@Vinjamuri: That’s what this does.
Timwi