Vb.net多个文本框事件发生变化

时间:2017-06-15 10:58:43

标签: vb.net object events textbox tooltip

如何更改所有TextBox的mausehover事件

Private Sub TextBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.MouseHover
    ToolTip1.SetToolTip(TextBox1, TextBox1.Text)
End Sub
Private Sub TextBox2_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.MouseHover
    ToolTip1.SetToolTip(TextBox2, TextBo2.Text)
End Sub
Private Sub TextBox3_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.MouseHover
    ToolTip1.SetToolTip(TextBox3, TextBox3.Text)
End Sub

如何以最短的方式将代码添加到所有文本框鼠标悬停事件中 感谢。

1 个答案:

答案 0 :(得分:1)

这是一种方法:

Private Sub TextBox_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.MouseHover, TextBox2.MouseHover, TextBox3.MouseHover
    Dim tbx = DirectCast(sender, TextBox)
    ToolTip1.SetToolTip(tbx, tbx.Text)
End Sub