vb.net – 如何确定什么类型的对象是事件的发件人?

前端之家收集整理的这篇文章主要介绍了vb.net – 如何确定什么类型的对象是事件的发件人?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
亲爱的我的子
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

现在,我希望根据用户传递的内容(面板或一个pBox或一个按钮)给onThisTable一个不同的值,但是我无法找到什么是正确的方式来比较它是什么类型的?

Private Sub skill_mouseHover(ByVal sender As System.Object,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相关文章