CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Feb 2003
    Location
    Oklahoma City, OK
    Posts
    63

    Rectangle on screen

    I'm drawing a rectangle on a graphics surface using Graphics.DrawRectangle method. I want to be able to change the size of it several times, programmatically. What is the best way to get rid of the old size on the graphics object, before drawing it's new size???

    Please help
    Last edited by phirestalker; March 13th, 2003 at 05:56 PM.

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    store it in Array or member var.
    - Software Architect

  3. #3
    Join Date
    Feb 2003
    Location
    Oklahoma City, OK
    Posts
    63
    what I mean is I draw a rectangle on the screen, and then I need to resize it on the screen. if I call the DrawRectangle again with the new size, it will then have 2 rectangles on the screen, I do not want the first rectangle when I draw the second one with the new size. What's the best way to delete the first one from the screen (when there is other stuff on the screen behind it)??

    I know of Graphics.Save and Graphics.Restore, but I was hoping for a different way
    Last edited by phirestalker; March 14th, 2003 at 02:01 PM.

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    you can use ArrayList class
    and store the previous or history of rectangles and go from there.

    Paresh
    - Software Architect

  5. #5
    Join Date
    Jan 2003
    Posts
    13
    You can call the 'Invalidate()' method, which will cause the form to become dirty and force a re-paint.

  6. #6
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    yes, but before even calling Invalidate or refresh u need to have history of rectangles ? isn't it !!!

    Paresh
    - Software Architect

  7. #7
    Join Date
    Jan 2003
    Posts
    13
    If there is only one rectangle ever drawn on the form, store that rect in a class variable.

  8. #8
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    and that's why I pointed to store in Array List to store if History of rectangles are required !!!

    Paresh
    - Software Architect

  9. #9
    Join Date
    Jan 2003
    Posts
    13
    What's the best way to delete the first one from the screen (when there is other stuff on the screen behind it)??
    I answered his direct question...

  10. #10
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    ok,
    never mind..
    - Software Architect

  11. #11
    Join Date
    Jan 2003
    Posts
    13
    no harm, no foul...

  12. #12
    Join Date
    Feb 2003
    Location
    Oklahoma City, OK
    Posts
    63
    ok I thought of that, but if I am going to be doing this a couple times per second, won't calling that cause a flicker effect? I am looking through the help, and I am trying to find a way to store what is where I'm going to draw the rectangle and save it before I draw it, and then when I go to draw a new rectangle I do the same thing, but first replace what was behind the first rectangle and then save behind the new one again and so on. The reason I need to do this, is I am writing a class SelectionBox to draw the equivelent of what a lot of windows programs have, I want this class to keep track of itself as an OBJECT like all classes should, so that only ONE rectangle is on the screen at a time for each instance, and each instance can be moved individualy

  13. #13
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    you could specify Graphics path and use Region and do the clipping for rectangles.

    Paresh
    - Software Architect

  14. #14
    Join Date
    Feb 2003
    Location
    Oklahoma City, OK
    Posts
    63
    ok guys the code is attatched to this post, for some reason it is not erasing the old rectangles, could you tell me what I'm doin wrong?
    Attached Files Attached Files

  15. #15
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    this is the basic class, could you copy the code for where this class is called so that it can be debugged atleast.

    Paresh
    - Software Architect

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured