在 TextChanged 内部我想获得包含文本框的控件
Inside TextChanged I want to get control which contains text box
我有几个使用相同 TextChanged 方法的文本框。我如何在此 TextChanged 方法中获取包含触发事件的文本框的对象?
触发事件的 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).
我有几个使用相同 TextChanged 方法的文本框。我如何在此 TextChanged 方法中获取包含触发事件的文本框的对象?
触发事件的 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).