我有几个使用相同TextChanged方法的文本框。如何在这个TextChanged方法中获取包含触发事件的文本框的对象?
答案 0 :(得分:0)
触发事件的TextBox
包含在事件处理程序的sender
参数中。你只需要写:
TextBox senderTB = (TextBox)sender;
Control container = senderTB.Parent;
//If container is custom
//You could cast or use as here depending on having a different parent is valid
MyControl customContainer = (MyControl)senderTB.Parent;
控件的容器位于Parent
属性(MSDN)。