Heres my sub:
Dim onThisTable as String ="Name"
Private Sub skill_mouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.MouseHover, button2.MouseHover, panel1.MouseHover, panel2.MouseHover, pbox1.MouseHover
descriptionLabel.Text = dbClass.getDescription(sender.Text, onThisTable)
End Sub
Now I wish to give onThisTable a different value depending what the user pass over (panel or a pbox or a button) but I cant find what is the correct way to compare what type it is ...
Private Sub skill_mouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.MouseHover, button2.MouseHover, panel1.MouseHover, panel2.MouseHover, pbox1.MouseHover
if sender is ( a button )
onThisTable = "Admin"
else if sender is ( a panel )
onThisTable = "dbObject"
else
onThisTable ="Name"
end if
descriptionLabel.Text = dbClass.getDescription(sender.Text, onThisTable)
End Sub
Object Sender is a parameter called Sender that contains a reference to the control/object that raised the event.
The sender parameter will reveal which Textbox was clicked. Private Sub FindIt( ByVal sender As System.Object, ByVal e As System.EventArgs. ) Handles TextBox1.
In the general object, the sender is one of the parameters in the C# language, and also, it is used to create the instance of the object, which is raised by the specific events on the application. That event is handled using the Eventhandler mechanism that is mostly handled and responsible for creating the objects.
Sender is the object that raised the event and e contains the data of the event. All events in . NET contain such arguments. EventArgs is the base class of all event arguments and doesn't say much about the event.
You can use the TypeOf keyword as descibed here (link)
If TypeOf sender Is Button Then
onThisTable = "Admin"
ElseIf TypeOf sender Is System.Windows.Forms.Panel Then
onThisTable = "dbObject"
Else
onThisTable = "Name"
End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With