从c#中的不同控件类访问函数 [英] Access the function from different control class in c#

查看:114
本文介绍了从c#中的不同控件类访问函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于从不同类访问函数的典型问题



我在一个类中有一个函数'internal void showpanel()'让我们假设'ctlDisplay'其中(在该函数中)我使用pnlDisplay名称的类,这是该控件中使用的面板的名称



我的问题是如何在另一个控件类中访问该函数。由于'pnlDisplay'我无法将该函数设置为静态。

请记住我可以在另一个控件类中创建该类'ctlDisplay'的对象(假设'ctlCall')但仍然由于'showpanel'中的'pnlDisplay'名称,我无法在另一个控制类中访问它



感谢U提前:)

I have a typical question about accessing a function from different class

I have a function 'internal void showpanel()' in one class let's suppose 'ctlDisplay' class in which (in that function) I used pnlDisplay name which is the name of panel used in that control

My question is how to access that function in another control class. As due to 'pnlDisplay' I can't able to make that function static.
Remember I can make an object of that class 'ctlDisplay' in another control class (let suppose 'ctlCall') but still due to that 'pnlDisplay' name inside 'showpanel' I can't able to access it in another control class

Thank U In Advance :)

推荐答案

如果其他控件类在同一个Assembly中(因为你方法中的internal修饰符需要,那么你需要调用的方法就是包含的正确实例) class。

因此,如果您在要调用showpanel的类中创建了ctlDisplay实例,那么只需使用该实例。

Provided the other control class is in the same Assembly (because the "internal" modifier on your method requires that, then all you need to call the method is the correct instance of the containing class.
So if you have created the ctlDisplay instance within the class in which you want to call showpanel, then just use that instance.
ctlPanel cp = new ctlPanel();
...
cp.showpanel();





如果您没有该实例,则根本无法调用它!



If you don't have the instance, then you can't call it at all!


这篇关于从c#中的不同控件类访问函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆