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#
  4. dragging line

dragging line

Scheduled Pinned Locked Moved C#
question
8 Posts 2 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.
  • H Offline
    H Offline
    HexaDeveloper
    wrote on last edited by
    #1

    hi,all how can i drag a line with mouse from a point to another and it is extended whenever i drag it with mouse thanx

    C 1 Reply Last reply
    0
    • H HexaDeveloper

      hi,all how can i drag a line with mouse from a point to another and it is extended whenever i drag it with mouse thanx

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If you want the line to disappear when the mouse is lifted, use the CreateGraphics method to draw it, otherwise you need to handle the paint event. Either way, you want to handle the mouse down, mouse move and mouse up events, you need to store the position where the mouse went down, and keep painting new lines from there to where they mouse is as you move it. What do you want to achieve ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      H 1 Reply Last reply
      0
      • C Christian Graus

        If you want the line to disappear when the mouse is lifted, use the CreateGraphics method to draw it, otherwise you need to handle the paint event. Either way, you want to handle the mouse down, mouse move and mouse up events, you need to store the position where the mouse went down, and keep painting new lines from there to where they mouse is as you move it. What do you want to achieve ?

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        H Offline
        H Offline
        HexaDeveloper
        wrote on last edited by
        #3

        hi, Christian i donot want it to disappear but tie two points (actually two images) and when i move image the line extended

        C 1 Reply Last reply
        0
        • H HexaDeveloper

          hi, Christian i donot want it to disappear but tie two points (actually two images) and when i move image the line extended

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          What do you mean, two images ? What do you want to do ? If you want to draw two lines that persist, you need to handle the paint event, then when you call Invalidate(), the paint event will redraw your form. Store a bool to say if the mouse button is down, and two points, one for each end of the line. Set both to the current mouse pos when the mouse goes down, set one to the mouse position when it moves, and in your paint event, draw a line between them, if the mouse is down ( via that flag you set )

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          H 1 Reply Last reply
          0
          • C Christian Graus

            What do you mean, two images ? What do you want to do ? If you want to draw two lines that persist, you need to handle the paint event, then when you call Invalidate(), the paint event will redraw your form. Store a bool to say if the mouse button is down, and two points, one for each end of the line. Set both to the current mouse pos when the mouse goes down, set one to the mouse position when it moves, and in your paint event, draw a line between them, if the mouse is down ( via that flag you set )

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            H Offline
            H Offline
            HexaDeveloper
            wrote on last edited by
            #5

            thanx Christian about ur question iam making a mobile simulator project and i want to tie for example mobile node with base station node thanx alot generator

            C 1 Reply Last reply
            0
            • H HexaDeveloper

              thanx Christian about ur question iam making a mobile simulator project and i want to tie for example mobile node with base station node thanx alot generator

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              OK, that's a little more complex, you need to then store the locations of 'objects' you want to draw lines between ( assuming you don't want to allow arbitrary lines to be drawn ).

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              H 1 Reply Last reply
              0
              • C Christian Graus

                OK, that's a little more complex, you need to then store the locations of 'objects' you want to draw lines between ( assuming you don't want to allow arbitrary lines to be drawn ).

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                H Offline
                H Offline
                HexaDeveloper
                wrote on last edited by
                #7

                ( assuming you don't want to allow arbitrary lines to be drawn ). what is the mean of this generator

                C 1 Reply Last reply
                0
                • H HexaDeveloper

                  ( assuming you don't want to allow arbitrary lines to be drawn ). what is the mean of this generator

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  You want lines to only be drawn between components, or just anywhere that people feel like it ?

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                  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