其他类的访问功能 [英] Access function from other Class

查看:86
本文介绍了其他类的访问功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VB.Net的新手.我有两个用户控件(ucMaster和ucDetail),想从ucDetails访问ucMaster的功能(即GenerateMember()).我使用的是以下代码片段,但由于错误而卡住了

ucDetail.vb

I am new to VB.Net. I have two user control(ucMaster and ucDetail) and want to access a function of ucMaster(ie GenerateMember()) from ucDetails. what is the code snippet for this i used the following but stuck with error

ucDetail.vb

objucmaster as new ucMaster
objMaster.GenerateMember()

推荐答案

如果您创建了两个用户控件,则需要在类定义中将GenerateMember指定为公共对象,例如

< pre>
公共子GenerateMember()
''''您的代码
结束子
</pre>

如果您因此继承使明细成为master的子代,则应将sub声明为protected.

< pre>
受保护的子GenerateMember()
''''您的代码
结束子
</pre>
If you created the two user controls, then in the class definition you need to specify the GenerateMember as public e.g.

<pre>
Public Sub GenerateMember()
''''Your code
End Sub
</pre>

If you inherit therefore making details a child of master, you should declare the sub as protected.

<pre>
Protected Sub GenerateMember()
''''Your code
End Sub
</pre>


这篇关于其他类的访问功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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