PC Review


Reply
Thread Tools Rate Thread

Complex Mouse Events Issues (I'm confused)

 
 
jcrouse
Guest
Posts: n/a
 
      18th Jul 2004
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


 
Reply With Quote
 
 
 
 
jcrouse
Guest
Posts: n/a
 
      18th Jul 2004
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" <me> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      18th Jul 2004
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:

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

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


"jcrouse" <me> wrote in message
news:%(E-Mail Removed)...
> 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" <me> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
jcrouse
Guest
Posts: n/a
 
      19th Jul 2004
Resolved!

"jcrouse" <me> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Confused about writing Page Events in C# ASP.NET kellygreer1 Microsoft ASP .NET 5 6th Feb 2008 11:54 PM
Confused about Repeater Events! Can anyone help? champ.supernova@gmail.com Microsoft ASP .NET 2 7th Mar 2007 02:41 PM
Confused about events and when they get fired. AndrewMBaldwin@gmail.com Microsoft ASP .NET 7 24th May 2006 08:51 AM
Confused by Delegate Events Michael Tissington Microsoft VB .NET 3 7th Jun 2005 04:38 AM
Complex queries for confused individual! CQMMAN Microsoft Access 0 11th Dec 2003 03:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:16 PM.