LineShape control not moving freely with cursor
-
Hi CP, I am having a LineShape control with MouseDown,MouseUP,MouseMove events.
Dim fdragging As Boolean = False
Dim StartX, startY As IntegerPrivate 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
-
Hi CP, I am having a LineShape control with MouseDown,MouseUP,MouseMove events.
Dim fdragging As Boolean = False
Dim StartX, startY As IntegerPrivate 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
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... -
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...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
-
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
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... -
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...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 IntegerPrivate 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
-
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 IntegerPrivate 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
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... -
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...