0

In Visual Studio 2010, I am using mouse events with LineShapes located inside a panel. I created a simple example that demonstrates a behavior that I can not explain and is holding up my project.

Public Class Form1
    Public Moused_Down_On_Line As Boolean = False
    Public Moused_Down_On_Panel As Boolean = False
    Public Moused_Move_Count As Integer = 0

    Private Sub Panel1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
        Moused_Move_Count += 1
        TextBox1.Text = Moused_Move_Count.ToString() + " (" + Moused_Down_On_Line.ToString + ", " + Moused_Down_On_Panel.ToString + ")"
    End Sub

    Private Sub Panel1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
        Moused_Down_On_Panel = True
    End Sub

    Private Sub LineShape1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseDown
        Moused_Down_On_Line = True
    End Sub

    Private Sub LineShape1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseUp, Panel1.MouseUp
        Moused_Down_On_Panel = False
        Moused_Down_On_Line = False
    End Sub

End Class

When I move the mouse over the Panel, TextBox1 shows that I am getting the expected MouseMove events.

When I click the mouse button over the Panel and hold it, TextBox1 still shows that I am getting the expected MouseMove events.

When I click the mouse button over the LineShape and hold it, however, TextBox1 shows that I am no longer getting the expected MouseMove events. Also, if I release the mouse button over the Panel, I also do not get the MouseUp event.

Can someone please explain to me what I am doing wrong? I really need to continue getting Mouse events for the Panel, after clicking on the LineShape!

Edited:

I added this event, but the TextBox shows that I only get MouseMove events when I move the mouse over the LineShape:

Private Sub LineShape1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LineShape1.MouseMove
    Moused_Move_Count += 1
    TextBox1.Text = "LineShape Event" + Moused_Move_Count.ToString() + " (" + Moused_Down_On_Line.ToString + ", " + Moused_Down_On_Panel.ToString + ")"
End Sub
BigBobby
  • 423
  • 1
  • 3
  • 17
  • This is entirely normal, the control you click captures the mouse. Maybe you want to add the LineShape's MouseMove event handler, maybe you want to add `ShapeContainer1.Capture = False` in the LineShape1_MouseDown event handler. Very unclear which would be best when you don't explain what you are trying to do. – Hans Passant Jun 17 '15 at 22:24
  • Thank you for your reply. Ultimately I am looking to drag the LineShapes around the Panel when I click on the LineShape and move the mouse around the Panel. – BigBobby Jun 17 '15 at 22:32
  • That makes using the LineShape's MouseMove event the most obvious candidate. Just add it. – Hans Passant Jun 17 '15 at 22:37
  • Won't I only get the LineShape's MouseMove events when I move the mouse over the LineShape? I need to get events when I move the mouse off of the LineShape, so that I can then modify the X & Y attributes depending upon where the mouse was moved. – BigBobby Jun 17 '15 at 22:48
  • The only mistake you can make is not trying it. – Hans Passant Jun 17 '15 at 23:02
  • I actually did try it before my last comment, although the "?" in my response made it sound like I had not. I edited my question to show the event I added, but the TextBox shows that I only get MouseMove events when I actually move the mouse over the LineShape. – BigBobby Jun 17 '15 at 23:07

1 Answers1

0

Thanks to Hans for explaining why I stopped getting Mouse events for my control panel. It seems like I effectively solved my problem by creating a RectangleShape in the same ShapeContainer as the LineShape. The RectangleShape was the size as the Panel, with a Custom BorderStyle and a Transparent FillStyle. Even after clicking on the LineShape and holding it, I'll still get MouseMove events for the RectangleShape.

BigBobby
  • 423
  • 1
  • 3
  • 17