Panel Events Stop After MouseDown event on LineShape

270 views Asked by At

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
1

There are 1 answers

0
BigBobby On

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.