我可以为VB.Net中的所有对象访问一个事件吗? [英] Can I Acess One Event for All objects in VB.Net

查看:106
本文介绍了我可以为VB.Net中的所有对象访问一个事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用诸如
之类的事件
私有子TextBox1_TextChanged(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理TextBox1.TextChanged,TextBox5.TextChanged,TextBox4.TextChanged,TextBox3.TextChanged,TextBox2.TextChanged

结束子

在这种情况下,我如何知道哪个对象称为该事件.
你能写一个例子吗?
Thnks ..

By Using Events Such as,

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox5.TextChanged, TextBox4.TextChanged, TextBox3.TextChanged, TextBox2.TextChanged

End Sub

In this event How Can I know which object is call this event.
Can U write a Example?
Thnks..

推荐答案

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox5.TextChanged, TextBox4.TextChanged, TextBox3.TextChanged, TextBox2.TextChanged	
  Select Case sender.Name
  Case "TextBox1"
    // Code for TextBox1 here
  Case "TextBox2"
    // Code for TextBox2 here
  Case "TextBox3"
    // Code for TextBox3 here
  Case "TextBox4"
    // Code for TextBox4 here
  Case "TextBox5"
    // Code for TextBox5 here
  Case Else
    // Ooops!
  End Select
End Sub


:)


将对象发送者投射到文本框,以了解哪个文本框触发了该事件.
Cast the object sender to a textbox to know which textbox fired the event.


这篇关于我可以为VB.Net中的所有对象访问一个事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆