Complex Mouse Events Issues (I'm confused)

J

jcrouse

I have created a form designer type application (with a lot of you peoples
helpJ). It has label controls that are draggable at runtime. The user is
also allowed to change some properties such as forecolor, backcolor and
font. The labels also are rotatable and the text can also be flipped 180
degrees (the flipped text part is still being worked on). I have one context
menu for all 30 labels that allows for the property changes to the labels.
As of now, the user can't edit any properties unless the label is first
selected. This is accomplished by holding down the ctrl key and left
clicking on the desired label or labels. This changes the border from none
to fixed single so the user can tell the label is selected. The properties
changes are the only applied to labels whose border style is fixed single
(kind of like a trigger). It also enables the menu items for the
above-mentioned properties in the context menu. The changes performed in the
context menu are then applied to all of the selected labels. What I'm
looking to be able to do is also just right click on any label and set its
individual properties. I am trying to use the distinction between the right
click and my above-mentioned ctrl left click. I'm getting lost in all of my
code with all these mouse events, mouse hover, mouse click, mouse down,
mouse move and mouse up events going on not to mention the toggling of all
the menu items enabled property. Mouse events are very difficult to debug J.
One of the other issues is the repainting of the labels which I have another
recent post about here on the board. I am sure there is a simpler way than
how I'm doing it. I posted my code below and am open to any suggestions on
how to make things simpler and work.



Private Sub lblP1JoyUp_MouseHover(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.MouseHover

lblP1JoyUp.Cursor = Cursors.SizeAll

End Sub



Private Sub lblP1JoyUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.Click

If bMouseMove = False Then

If bCtrlKey = True Then

If lblP1JoyUp.BorderStyle = BorderStyle.None Then

lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle

AddLabel(frm1.Controls)

bLabelSelected = True

ElseIf lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle Then

lblP1JoyUp.BorderStyle = BorderStyle.None

bLabelSelected = False

End If

End If

End If

Me.Refresh()

End Sub



Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseDown

If e.Button = MouseButtons.Left Then

myMousedown = lblP1JoyUp.Name

bMouseMove = False

lblP1JoyUp.BringToFront()

mouseX = Cursor.Position.X - lblP1JoyUp.Location.X

mouseY = Cursor.Position.Y - lblP1JoyUp.Location.Y

lblP1JoyUp.Cursor = Cursors.Hand

ElseIf e.Button = MouseButtons.Right Then

No Code Here Yet!

End If

End Sub



Private Sub lblP1JoyUp_MouseMove(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseMove

Dim lblP1JoyUp As Label = DirectCast(sender, Label)

Static LastCursor As Point

Dim NowCursor As Point = New Point(Cursor.Position.X, Cursor.Position.Y)

If Point.op_Inequality(NowCursor, LastCursor) Then

If myMousedown = lblP1JoyUp.Name Then

If lblP1JoyUp.BackColor.Equals(Color.Transparent) Then

clrBGColor = lblP1JoyUp.BackColor

bTransCk = True

lblP1JoyUp.BackColor = clrLabelMove

End If

lblP1JoyUp.Location = New System.Drawing.Point(Cursor.Position.X -
mouseX, Cursor.Position.Y - mouseY)

bMouseMove = True

bSavedLayoutTrigger = False

End If

LastCursor = Cursor.Position

End If

End Sub



Private Sub lblP1JoyUp_MouseUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseUp

Dim lblP1JoyUp As Label = DirectCast(sender, Label)

If bTransCk = True Then

bTransCk = False

lblP1JoyUp.BackColor = clrBGColor

End If

myMousedown = ""

lblP1JoyUp.Cursor = Cursors.Default

End Sub



So what do you think,

John
 
J

jcrouse

I have found a way do accomplish what I'm after, I think. Like I said, I
have 30 labels all sharing one context menu. As an example the is a menu
item in the context menu to change label.backcolor. When this menu item is
click it goes to a public sub which has code for ALL 30 labels. How can I
tell from which label the context menu was launched? This should be pretty
simple.

John


jcrouse said:
I have created a form designer type application (with a lot of you peoples
helpJ). It has label controls that are draggable at runtime. The user is
also allowed to change some properties such as forecolor, backcolor and
font. The labels also are rotatable and the text can also be flipped 180
degrees (the flipped text part is still being worked on). I have one context
menu for all 30 labels that allows for the property changes to the labels.
As of now, the user can't edit any properties unless the label is first
selected. This is accomplished by holding down the ctrl key and left
clicking on the desired label or labels. This changes the border from none
to fixed single so the user can tell the label is selected. The properties
changes are the only applied to labels whose border style is fixed single
(kind of like a trigger). It also enables the menu items for the
above-mentioned properties in the context menu. The changes performed in the
context menu are then applied to all of the selected labels. What I'm
looking to be able to do is also just right click on any label and set its
individual properties. I am trying to use the distinction between the right
click and my above-mentioned ctrl left click. I'm getting lost in all of my
code with all these mouse events, mouse hover, mouse click, mouse down,
mouse move and mouse up events going on not to mention the toggling of all
the menu items enabled property. Mouse events are very difficult to debug J.
One of the other issues is the repainting of the labels which I have another
recent post about here on the board. I am sure there is a simpler way than
how I'm doing it. I posted my code below and am open to any suggestions on
how to make things simpler and work.



Private Sub lblP1JoyUp_MouseHover(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.MouseHover

lblP1JoyUp.Cursor = Cursors.SizeAll

End Sub



Private Sub lblP1JoyUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.Click

If bMouseMove = False Then

If bCtrlKey = True Then

If lblP1JoyUp.BorderStyle = BorderStyle.None Then

lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle

AddLabel(frm1.Controls)

bLabelSelected = True

ElseIf lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle Then

lblP1JoyUp.BorderStyle = BorderStyle.None

bLabelSelected = False

End If

End If

End If

Me.Refresh()

End Sub



Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseDown

If e.Button = MouseButtons.Left Then

myMousedown = lblP1JoyUp.Name

bMouseMove = False

lblP1JoyUp.BringToFront()

mouseX = Cursor.Position.X - lblP1JoyUp.Location.X

mouseY = Cursor.Position.Y - lblP1JoyUp.Location.Y

lblP1JoyUp.Cursor = Cursors.Hand

ElseIf e.Button = MouseButtons.Right Then

No Code Here Yet!

End If

End Sub



Private Sub lblP1JoyUp_MouseMove(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseMove

Dim lblP1JoyUp As Label = DirectCast(sender, Label)

Static LastCursor As Point

Dim NowCursor As Point = New Point(Cursor.Position.X, Cursor.Position.Y)

If Point.op_Inequality(NowCursor, LastCursor) Then

If myMousedown = lblP1JoyUp.Name Then

If lblP1JoyUp.BackColor.Equals(Color.Transparent) Then

clrBGColor = lblP1JoyUp.BackColor

bTransCk = True

lblP1JoyUp.BackColor = clrLabelMove

End If

lblP1JoyUp.Location = New
System.Drawing.Point(Cursor.Position.X -
 
J

Jay B. Harlow [MVP - Outlook]

John,
The sender parameter of the Click event is the Label that was clicked.

For example you could have a single Click event handler that handles 3
labels: lblP1JoyUp, lblP2JoyUp, and lblP3JoyUp something like:
lblP3JoyUp.Click

Dim label As Label = DirectCast(sender, Label)
' label now references the Label control that was clicked!

Within Label_Click, you can use the sender parameter to identify which label
was clicked.

Hope this helps
Jay
 
J

jcrouse

Resolved!

jcrouse said:
I have created a form designer type application (with a lot of you peoples
helpJ). It has label controls that are draggable at runtime. The user is
also allowed to change some properties such as forecolor, backcolor and
font. The labels also are rotatable and the text can also be flipped 180
degrees (the flipped text part is still being worked on). I have one context
menu for all 30 labels that allows for the property changes to the labels.
As of now, the user can't edit any properties unless the label is first
selected. This is accomplished by holding down the ctrl key and left
clicking on the desired label or labels. This changes the border from none
to fixed single so the user can tell the label is selected. The properties
changes are the only applied to labels whose border style is fixed single
(kind of like a trigger). It also enables the menu items for the
above-mentioned properties in the context menu. The changes performed in the
context menu are then applied to all of the selected labels. What I'm
looking to be able to do is also just right click on any label and set its
individual properties. I am trying to use the distinction between the right
click and my above-mentioned ctrl left click. I'm getting lost in all of my
code with all these mouse events, mouse hover, mouse click, mouse down,
mouse move and mouse up events going on not to mention the toggling of all
the menu items enabled property. Mouse events are very difficult to debug J.
One of the other issues is the repainting of the labels which I have another
recent post about here on the board. I am sure there is a simpler way than
how I'm doing it. I posted my code below and am open to any suggestions on
how to make things simpler and work.



Private Sub lblP1JoyUp_MouseHover(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.MouseHover

lblP1JoyUp.Cursor = Cursors.SizeAll

End Sub



Private Sub lblP1JoyUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.Click

If bMouseMove = False Then

If bCtrlKey = True Then

If lblP1JoyUp.BorderStyle = BorderStyle.None Then

lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle

AddLabel(frm1.Controls)

bLabelSelected = True

ElseIf lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle Then

lblP1JoyUp.BorderStyle = BorderStyle.None

bLabelSelected = False

End If

End If

End If

Me.Refresh()

End Sub



Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseDown

If e.Button = MouseButtons.Left Then

myMousedown = lblP1JoyUp.Name

bMouseMove = False

lblP1JoyUp.BringToFront()

mouseX = Cursor.Position.X - lblP1JoyUp.Location.X

mouseY = Cursor.Position.Y - lblP1JoyUp.Location.Y

lblP1JoyUp.Cursor = Cursors.Hand

ElseIf e.Button = MouseButtons.Right Then

No Code Here Yet!

End If

End Sub



Private Sub lblP1JoyUp_MouseMove(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseMove

Dim lblP1JoyUp As Label = DirectCast(sender, Label)

Static LastCursor As Point

Dim NowCursor As Point = New Point(Cursor.Position.X, Cursor.Position.Y)

If Point.op_Inequality(NowCursor, LastCursor) Then

If myMousedown = lblP1JoyUp.Name Then

If lblP1JoyUp.BackColor.Equals(Color.Transparent) Then

clrBGColor = lblP1JoyUp.BackColor

bTransCk = True

lblP1JoyUp.BackColor = clrLabelMove

End If

lblP1JoyUp.Location = New
System.Drawing.Point(Cursor.Position.X -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top