0
votes

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
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
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
That makes using the LineShape's MouseMove event the most obvious candidate. Just add it.Hans Passant
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
The only mistake you can make is not trying it.Hans Passant

1 Answers

0
votes

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.