如何在用户控件内使用或调用用户控件 [英] How to use or call user control inside user control
问题描述
请任何好友帮我如何在用户控制中调用用户控件。
我必须用户控制,以便我想将一个用户控件的所有方法调用到其他用户。
所以给我一些代码,以便我可以在我的项目中实现。
假设用户控件A有对用户控件B的引用...
假设您想要访问的方法是公开的。
从A中你可以简单地做到< br $> b $ b
instanceOfB.SomeMethod();
如果你想在同样的情况下从B访问A的方法,你必须给B一个A的引用。
一种方法可以做到这一点be,in a
B.InstanceOfA = this ;
其中InstanceOfA是B中的物业
现在B可以调用方法A使用
<前lang =c#> InstanceOfA.SomeMethod();
有更好的方法来处理这个但它们都取决于什么类型的项目你正在处理 - 你没有给我们很多东西继续!
Please Any buddy help me how to call user control inside user control.
I have to user control so that i want to call all the methods of one user control to other.
so give me some code so that i can implement in my project.
Assuming user control A has a reference to User Control B...
Assuming the methods yo u want to access are public.
From within A you can simply do
instanceOfB.SomeMethod();
If you want to access methods of A from B in the same situationm, you will have to give B a reference to A.
One way to do this would be, in A
B.InstanceOfA = this;
where InstanceOfA is a property in B
Now B can call methods of A using
InstanceOfA.SomeMethod();
There are better ways of handling this but they all depend on what sort of project you're dealing with - and you haven't given us a lot to go on!
这篇关于如何在用户控件内使用或调用用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!