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. Visual Basic
  4. LineShape control not moving freely with cursor

LineShape control not moving freely with cursor

Scheduled Pinned Locked Moved Visual Basic
designtutorial
7 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.
  • F Offline
    F Offline
    for1206
    wrote on last edited by
    #1

    Hi CP, I am having a LineShape control with MouseDown,MouseUP,MouseMove events.

    Dim fdragging As Boolean = False
    Dim StartX, startY As Integer

    Private Sub LineShape1\_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseDown
        fdragging = True
        StartX = e.X
        startY = e.Y
    End Sub
    
    Private Sub LineShape1\_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseMove
        If fdragging Then
            LineShape1.StartPoint = New Point(LineShape1.StartPoint.X + e.X - StartX, LineShape1.StartPoint.Y + e.Y - startY)
            LineShape1.EndPoint = New Point(LineShape1.EndPoint.X + e.X - StartX, LineShape1.EndPoint.Y + e.Y - startY)
            
        End If
    End Sub
    
    Private Sub LineShape1\_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ShapeContainer1.MouseUp
        fdragging = False
        StartX = 0
        startY = 0
    End Sub
    

    Now i am not able to move the lineshape control freely around the form with cursor like in the design time . Cursor is changing the location so slipping happens . How to stick the cursor to LineShape control. Regards,

    For1206

    D 1 Reply Last reply
    0
    • F for1206

      Hi CP, I am having a LineShape control with MouseDown,MouseUP,MouseMove events.

      Dim fdragging As Boolean = False
      Dim StartX, startY As Integer

      Private Sub LineShape1\_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseDown
          fdragging = True
          StartX = e.X
          startY = e.Y
      End Sub
      
      Private Sub LineShape1\_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseMove
          If fdragging Then
              LineShape1.StartPoint = New Point(LineShape1.StartPoint.X + e.X - StartX, LineShape1.StartPoint.Y + e.Y - startY)
              LineShape1.EndPoint = New Point(LineShape1.EndPoint.X + e.X - StartX, LineShape1.EndPoint.Y + e.Y - startY)
              
          End If
      End Sub
      
      Private Sub LineShape1\_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ShapeContainer1.MouseUp
          fdragging = False
          StartX = 0
          startY = 0
      End Sub
      

      Now i am not able to move the lineshape control freely around the form with cursor like in the design time . Cursor is changing the location so slipping happens . How to stick the cursor to LineShape control. Regards,

      For1206

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You're having problems because you're mixing the mouse coordinates on the control itself and the mouse coordinates on the controls parent container. Read my article on Create your own runtime movable Windows Forms controls[^] to understand the difference.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      F 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You're having problems because you're mixing the mouse coordinates on the control itself and the mouse coordinates on the controls parent container. Read my article on Create your own runtime movable Windows Forms controls[^] to understand the difference.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        F Offline
        F Offline
        for1206
        wrote on last edited by
        #3

        Hi Dave , Already i am having selections , The problem is on mousemove the line control is moving but if the cursor goes out of the line control its not handling the mousemove i.e, Slipping of Cursor on the cursor . I tried to set the cursor location on the control but not working fine . Regards,

        For1206

        D 1 Reply Last reply
        0
        • F for1206

          Hi Dave , Already i am having selections , The problem is on mousemove the line control is moving but if the cursor goes out of the line control its not handling the mousemove i.e, Slipping of Cursor on the cursor . I tried to set the cursor location on the control but not working fine . Regards,

          For1206

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          You didn't read the article. The problem you're concentrating on handling the mouse move in the LineControl's events. DON'T! The mouse is actually moving in the parent container of the LineControl. This is why your code doesn't work.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          F 1 Reply Last reply
          0
          • D Dave Kreskowiak

            You didn't read the article. The problem you're concentrating on handling the mouse move in the LineControl's events. DON'T! The mouse is actually moving in the parent container of the LineControl. This is why your code doesn't work.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            F Offline
            F Offline
            for1206
            wrote on last edited by
            #5

            Hi Dave , Thanks for reply & Thanks for the Link ,Presently i am using ur code in my application for changing the line startpoint and endpoint and dragging the line also. Can u suggest me in a sample program that how can i move a LineShape control freely around the form with cursor without slipping . This is happening in a sample new form. This is the code i used & its slipping from cursor .

            Dim fdragging As Boolean = False
            Dim StartX, startY As Integer

            Private Sub LineShape1\_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseDown
                fdragging = True
                StartX = e.X
                startY = e.Y
            End Sub
            
            Private Sub LineShape1\_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseMove
                Cursor.Current = Cursors.SizeAll
                If fdragging Then
                    LineShape1.StartPoint = New Point(LineShape1.StartPoint.X + e.X - StartX, LineShape1.StartPoint.Y + e.Y - startY)
                    LineShape1.EndPoint = New Point(LineShape1.EndPoint.X + e.X - StartX, LineShape1.EndPoint.Y + e.Y - startY)
                End If
            End Sub
            
            Private Sub LineShape1\_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ShapeContainer1.MouseUp
                fdragging = False
                StartX = 0
                startY = 0
            End Sub
            

            its important for me . plz can u suggest any work around ? Regards,

            For1206

            modified on Tuesday, February 23, 2010 1:57 AM

            D 1 Reply Last reply
            0
            • F for1206

              Hi Dave , Thanks for reply & Thanks for the Link ,Presently i am using ur code in my application for changing the line startpoint and endpoint and dragging the line also. Can u suggest me in a sample program that how can i move a LineShape control freely around the form with cursor without slipping . This is happening in a sample new form. This is the code i used & its slipping from cursor .

              Dim fdragging As Boolean = False
              Dim StartX, startY As Integer

              Private Sub LineShape1\_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseDown
                  fdragging = True
                  StartX = e.X
                  startY = e.Y
              End Sub
              
              Private Sub LineShape1\_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseMove
                  Cursor.Current = Cursors.SizeAll
                  If fdragging Then
                      LineShape1.StartPoint = New Point(LineShape1.StartPoint.X + e.X - StartX, LineShape1.StartPoint.Y + e.Y - startY)
                      LineShape1.EndPoint = New Point(LineShape1.EndPoint.X + e.X - StartX, LineShape1.EndPoint.Y + e.Y - startY)
                  End If
              End Sub
              
              Private Sub LineShape1\_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ShapeContainer1.MouseUp
                  fdragging = False
                  StartX = 0
                  startY = 0
              End Sub
              

              its important for me . plz can u suggest any work around ? Regards,

              For1206

              modified on Tuesday, February 23, 2010 1:57 AM

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Read the article. I don't have time to write an entire sample app for you.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008
              But no longer in 2009...

              F 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Read the article. I don't have time to write an entire sample app for you.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008
                But no longer in 2009...

                F Offline
                F Offline
                for1206
                wrote on last edited by
                #7

                Hi Dave, Thanks 4 reply . I already implemented your code in my application .Its made a nice job for me. Thank you very much . Regards,

                For1206

                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