how can i know what event was triggered in picturebox in VBnet?
in vbnet code:
Private Sub picButton_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles picButton.MouseEnter
'CODE HERE'
End Sub
Private Sub picButton_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles picButton.MouseLeave
'CODE HERE'
End Sub
and i want to make it like this:
Private Sub picButtonEVent(ByVal sender As Object, ByVal e As System.EventArgs) Handles picButton.MouseLeave, picButton.MouseEnter
'CODE HERE'
'If MouseEnter Then'
'Code for mouseEnter'
'ElseIf MouseLeave Then'
'Code for mouseLeave'
'End If'
End Sub
i want to know what event was triggered whether it is .MouseEnter or .MouseLeave. the reason why i’m making this is to make the code more categorized according to the object that was used.
One thing you could do is to create a helper function that takes an additional Enum parameter that you can use to determine the event type, and then you can just enclose the dummy events in a region so you can collapse them. Off-hand, I don’t know of an elegant way to determine what event actually fired from the event itself (that is, without using Reflection…)
My suggestion:
Edit:
As mentioned before, Reflection is a possibility, though not ideal due to the amount of overhead involved (especially in the case of events like these which could be called quite frequently). That being said, I whipped up a working example using Reflection simply to illustrate that it’s possible. (Actually
StackTrace, which is what I used, is inSystem.Diagnostics. Not exactlyReflectionbut it’s close enough for me…)Please don’t send the raptors…