Thread: Making a moveable rectanlge on top of an image

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485

    Making a moveable rectanlge on top of an image

    Hey

    I am working on a small program where I need to be able to place rectangles on top of an image. The rectangles has to be able to be move and scaled using the mouse. What is the best way to do this?

    I was thinking of storing the coordinates of each rectangle, and every time the mouse is pressed inside the image I do a check against the coordinates to see if the mouse is inside one of the rectangles. And I would draw then using a brush on top of the image. But to me this does not sound like a very good way of doing this, so I am wondering if its a better way I could go about it?

    Im using c# if that helps in any way.

    Regards,

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It seems like a reasonable approach to begin with.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I usually do it some thing like..

    left button down is the trigger to start the rectangle (clear old). This is your start position. Draw a dot.

    check mouse move msgs to see if the left mouse is down, if it is get the current mouse position and expand the rectangle. Draw.

    check for left button up and draw the rectangle.

    How you do the drawing depends on the complexity of your background / drawing (speed needed to avoid flickering/shearing).

    EDIT:
    Look at PtInRect()
    Beware of screen / client coordinates (and offsets from these to a control).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Resizing an Image to Cover Top
    By Speedy5 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 06-11-2003, 01:34 PM
  2. Replies: 4
    Last Post: 03-02-2003, 09:12 AM
  3. Changing a treeview item's image
    By SMurf in forum Windows Programming
    Replies: 0
    Last Post: 01-14-2003, 07:08 PM
  4. Image rotation using intel image processing
    By sunis in forum Windows Programming
    Replies: 1
    Last Post: 11-18-2002, 02:40 AM
  5. How to change a mouse cursor in console mode
    By GaPe in forum Windows Programming
    Replies: 10
    Last Post: 07-03-2002, 07:42 AM