By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,238 Members | 1,485 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,238 IT Pros & Developers. It's quick & easy.

Sharing common events

P: n/a
I am trying to share mouse events (click, up, down, move and the such) for
30 different label controls: Here is my code:

Dim myLabel as Label

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

myLabel = lblP1JoyUp

myLabelMouseDown()

End Sub

Public Sub myLabelMouseDown()

If e.Button = MouseButtons.Left Then

My code here

ElseIf e.Button = MouseButtons.Right Then

My code here

End If

End Sub
The problem is that it tells me "e" isn't declared. Am I missing something
with my handlers? I thought I had this working at one time with help from
Cor but can't find it no how.

Thanks,
John

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I seem to have found Cor's example and a post from Jay. I'll give it another
go.

John

"jcrouse" <me> wrote in message
news:ur**************@TK2MSFTNGP09.phx.gbl...
I am trying to share mouse events (click, up, down, move and the such) for
30 different label controls: Here is my code:

Dim myLabel as Label

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

myLabel = lblP1JoyUp

myLabelMouseDown()

End Sub

Public Sub myLabelMouseDown()

If e.Button = MouseButtons.Left Then

My code here

ElseIf e.Button = MouseButtons.Right Then

My code here

End If

End Sub
The problem is that it tells me "e" isn't declared. Am I missing something
with my handlers? I thought I had this working at one time with help from
Cor but can't find it no how.

Thanks,
John


Nov 21 '05 #2

P: n/a
>
Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseDown

myLabel = lblP1JoyUp

myLabelMouseDown()
change this to: myLabelMouseDown(e)

End Sub
Public Sub myLabelMouseDown()
and this to: Public Sub myLabelMouseDown(ByVal e as
System.Windows.Forms.MouseEventArgs)

If e.Button = MouseButtons.Left Then

My code here

ElseIf e.Button = MouseButtons.Right Then

My code here

End If

End Sub
The problem is that it tells me "e" isn't declared.


That's exactly what that means. In the procedure myLabelMouseDown 'e' hasn't
been declared anywhere.
hope this helps..
Imran.
Nov 21 '05 #3

P: n/a
* "jcrouse" <me> scripsit:
I am trying to share mouse events (click, up, down, move and the such) for
30 different label controls: Here is my code:

Dim myLabel as Label

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

myLabel = lblP1JoyUp

myLabelMouseDown()

End Sub


Instead of adding one handler per control, add a common handler. To do
that, add all 30 controls to the 'Handles...' list at the procedure
head's end ('Handles Label1.MouseDown, Handles Label2.MouseDown, ...'),
or use 'AddHandler to add the common handler to all of the controls'
'MouseDown' event. Then you can check the event handler's 'sender'
parameter to see which control caused the event:

\\\
Dim SourceControl As Control = DirectCast(sender, Control)
....
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4

P: n/a
Got it resolved!

Thanks for your patience guys,
John
"jcrouse" <me> wrote in message
news:ur**************@TK2MSFTNGP09.phx.gbl...
I am trying to share mouse events (click, up, down, move and the such) for
30 different label controls: Here is my code:

Dim myLabel as Label

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

myLabel = lblP1JoyUp

myLabelMouseDown()

End Sub

Public Sub myLabelMouseDown()

If e.Button = MouseButtons.Left Then

My code here

ElseIf e.Button = MouseButtons.Right Then

My code here

End If

End Sub
The problem is that it tells me "e" isn't declared. Am I missing something
with my handlers? I thought I had this working at one time with help from
Cor but can't find it no how.

Thanks,
John


Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.