简体   繁体   English

更新面板中添加的UserControl

[英]Update UserControl that has been added in Panel

I have a ContainerPanel to which I added a UserControl. 我有一个ContainerPanel,向其中添加了UserControl。

Is there a way to access the already added UserControl in order to call an Update Function that has been already declared inside the UserControl? 有没有一种方法可以访问已添加的UserControl以便调用已在UserControl中声明的Update Function?

or 要么

Is it better just to clear the Usercontrol and Re-load it with the updated info? 清除用户控件并重新加载更新的信息是否更好?

Cheers, 干杯,

You could search the panels children for the type you're trying to find (I'm using Linq in the example below). 您可以在面板子级中搜索要查找的类型(在下面的示例中,我使用的是Linq)。

var myControl = myPanel.Controls.OfType<MyUserControl>().FirstOrDefault();
myControl.DoWhatever();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM