Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to move rectangle with mouse

How to move rectangle with mouse

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialgraphics
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raju_shiva
    wrote on last edited by
    #1

    Hi all, I am drawing a rectangle using LineTo(HDC hdc,x,y). Now i planning to move or change the rectangle using mouse. For example:If i click the mouse on the rectangle line,then i can drag the rectangle line using mouse. Any idea will be helpful Thanks Raj

    L _ 2 Replies Last reply
    0
    • R raju_shiva

      Hi all, I am drawing a rectangle using LineTo(HDC hdc,x,y). Now i planning to move or change the rectangle using mouse. For example:If i click the mouse on the rectangle line,then i can drag the rectangle line using mouse. Any idea will be helpful Thanks Raj

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to capture the mouse co-ordinates as you drag and then use those values in your paint routine to redraw the rectangle either at a new position in your window or as a new size, depending on how your program is designed.

      It's time for a new signature.

      1 Reply Last reply
      0
      • R raju_shiva

        Hi all, I am drawing a rectangle using LineTo(HDC hdc,x,y). Now i planning to move or change the rectangle using mouse. For example:If i click the mouse on the rectangle line,then i can drag the rectangle line using mouse. Any idea will be helpful Thanks Raj

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        Firstly, you do not need to use LineTo to draw a rectangle. Use the Rectangle function instead. Secondly, you can achieve the same behavior using the CRectTracker class if you're using MFC.

        «_Superman_»
        I love work. It gives me something to do between weekends.

        Microsoft MVP (Visual C++)

        Polymorphism in C

        R 1 Reply Last reply
        0
        • _ _Superman_

          Firstly, you do not need to use LineTo to draw a rectangle. Use the Rectangle function instead. Secondly, you can achieve the same behavior using the CRectTracker class if you're using MFC.

          «_Superman_»
          I love work. It gives me something to do between weekends.

          Microsoft MVP (Visual C++)

          Polymorphism in C

          R Offline
          R Offline
          raju_shiva
          wrote on last edited by
          #4

          Hi, Thanks for your reply.The reason i used LineTo is. I have to draw to a rectangle and rotate with the given degree.I found it hard with Rectangle function. I am calculating the axis with the given degree and values first, and then drawing the lines with that axis to complete the rectangle. Now i want is : If i click the mouse on any of the line on rectangle.Mouse has to ba activated so that i can move the line and resize the rectangle.' I am confused ,how to start it. thanks Raj

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups