C# 在TextChanged内部,我想获得包含文本框的控件

C# 在TextChanged内部,我想获得包含文本框的控件,c#,textbox,C#,Textbox,我有几个使用相同TextChanged方法的文本框。如何在这个TextChanged方法中获取包含触发事件的文本框的对象 触发事件的文本框包含在事件处理程序的sender参数中。你只需要写: TextBox senderTB = (TextBox)sender; Control container = senderTB.Parent; //If container is custom //You could cast or use as here depending on having a d

我有几个使用相同TextChanged方法的文本框。如何在这个TextChanged方法中获取包含触发事件的文本框的对象

触发事件的
文本框
包含在事件处理程序的
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;

控件的容器位于父属性()中。

谢谢,但我不需要文本框,我需要包含此文本框的控件(例如,面板)@lit17已更新以显示父属性的使用情况。

property@lit17应用了第二次编辑。如果你愿意的话,你可以发表评论:)不需要建议编辑时加上“谢谢”之类的字眼。