none
MFC: Draw rectangle inside a rectangle RRS feed

  • Question

  • Hi,

    I have drawn a rectangle:

    dc.Rectangle(10,10,200,100);

    Now i want to draw rectangle inside it by reducing 10 from each side. i.e the new rectangle will be: CRect(20,20,190,90).

    I am manually adjusting the co-ordinate, Is there any API to do this.

    offsetRect() is not solving my issue.

    Thanks

    Wednesday, February 25, 2015 11:14 AM

Answers

  • Hi,

    I have drawn a rectangle:

    dc.Rectangle(10,10,200,100);

    Now i want to draw rectangle inside it by reducing 10 from each side. i.e the new rectangle will be: CRect(20,20,190,90).

    I am manually adjusting the co-ordinate, Is there any API to do this.

    offsetRect() is not solving my issue.

    Thanks

    Just write yourself a function and use it as needed. Programming is not manual work; the computer does the heavy lifting.

    Edit: Actually, I think CRect::DeflateRect() does what you want.


    David Wilkinson | Visual C++ MVP


    • Edited by davewilk Wednesday, February 25, 2015 2:00 PM
    • Proposed as answer by SimonRev Wednesday, February 25, 2015 3:04 PM
    • Marked as answer by Shu 2017Moderator Monday, March 2, 2015 1:34 AM
    Wednesday, February 25, 2015 12:09 PM
  • Hi,

    I found the answer

    Its deflateRect.

    Thanks

    • Marked as answer by LokanathNayak Friday, February 27, 2015 1:06 PM
    Friday, February 27, 2015 1:06 PM

All replies

  • Hi,

    I have drawn a rectangle:

    dc.Rectangle(10,10,200,100);

    Now i want to draw rectangle inside it by reducing 10 from each side. i.e the new rectangle will be: CRect(20,20,190,90).

    I am manually adjusting the co-ordinate, Is there any API to do this.

    offsetRect() is not solving my issue.

    Thanks

    Just write yourself a function and use it as needed. Programming is not manual work; the computer does the heavy lifting.

    Edit: Actually, I think CRect::DeflateRect() does what you want.


    David Wilkinson | Visual C++ MVP


    • Edited by davewilk Wednesday, February 25, 2015 2:00 PM
    • Proposed as answer by SimonRev Wednesday, February 25, 2015 3:04 PM
    • Marked as answer by Shu 2017Moderator Monday, March 2, 2015 1:34 AM
    Wednesday, February 25, 2015 12:09 PM
  • On 2/25/2015 6:14 AM, LokanathNayak wrote:

    offsetRect() is not solving my issue.

    Why not? What do you feel is wrong with it?


    Igor Tandetnik
    Wednesday, February 25, 2015 1:28 PM
  • Hi,

    I found the answer

    Its deflateRect.

    Thanks

    • Marked as answer by LokanathNayak Friday, February 27, 2015 1:06 PM
    Friday, February 27, 2015 1:06 PM
  • I found the answer

    Its deflateRect.

    Isn't that what I told you?


    David Wilkinson | Visual C++ MVP

    Friday, February 27, 2015 1:10 PM