这是我的潜艇:

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

现在,我希望给onThisTable一个不同的值,具体取决于用户传递的内容(面板,pbox或按钮),但是我找不到比较它是什么类型的正确方法...
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

最佳答案

您可以使用此处描述的TypeOf关键字(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

关于vb.net - 如何确定事件的发送者是什么类型的对象?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8270788/

10-09 14:30