在Form中调用public sub [英] calling public sub in Form
问题描述
为什么我不能在模块或类中调用我的
应用程序主窗体中定义的公共函数或子函数,所有都是
同一个程序集的一部分?
当我在一个类中定义公共函数时,我可以从表单中调用它,
但是如果我在表单中定义公共函数并尝试从
类调用它,它就不起作用。不知道我做错了什么?
谢谢,
Strah
***通过Developersdex发送< a rel =nofollowhref =http://www.developersdex.comtarget =_ blank> http://www.developersdex.com ***
Don 只是参加USENET ......获得奖励!
你可以,但你需要有一个类的实例打电话给它,除非
这是一个共享的方法。
// SomeModule
Dim F as New Foo
F.SomeSub< - 这样可以正常工作
// SomeBadModule
F.SomeSub< - 仅在共享时有效
Class Foo
Public Sub SomeSub()
End Sub
End上课
希望这可以解决它。
Chris
Strahimir Antoljak < SA ******* @ langan.com>在消息中写道
news:em ************** @ TK2MSFTNGP10.phx.gbl ...
<为什么我不能在模块或类中调用我的
应用程序主窗体中定义的公共函数或子函数,它们都是同一个程序集的一部分?
当我在一个类中定义公共函数时,我可以从表单中调用它,
但如果我在表单中定义公共函数并尝试从
类调用它,它会不行。知道我做错了什么吗?
谢谢,
***通过Developersdex发送 http://www.developersdex.com ***
不要只是参加USENET ......获得奖励对于它!
你好Chris,
您的输入有帮助。我正在创建
Windows.System.Forms.Form的新实例,而不是我的表单......它通过查看你的代码帮助我看到我的
错误。谢谢,
Strah
***通过Developersdex发送 http://www.developersdex.com ***
不要只是参加USENET ......获得奖励!
" Strahimir Antoljak" < SA ******* @ langan.com> schrieb:为什么我不能在模块或类中调用我的
应用程序主窗体中定义的公共函数或子函数,所有这些都是
相同的汇编?
如果您参考主表单的实例
模块可用,您可以这样做。
提供对应用程序主表单的引用
< URL:http://dotnet.mvps.org/dotnet/faqs/ ?id = accessmainform& lang = zh>
-
MS Herfried K. Wagner
MVP< URL:http ://dotnet.mvps.org/>
VB< URL:http://dotnet.mvps.org/dotnet/faqs/>
Why can''t I call a public function or sub defined in the main form of my
application from within a module or a class, all being a part of the
same assembly?
When I define public function in a class, I can call it from the form,
but if I define public function in the form and try to call it from the
class it does not work. Any idea what am I doing wrong?
Thanks,
Strah
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!
You can, but you need to have an instance of the class to call it on, unless
it''s a shared method.
//SomeModule
Dim F as New Foo
F.SomeSub <--This works fine
//SomeBadModule
F.SomeSub <-- Only works if Shared
Class Foo
Public Sub SomeSub()
End Sub
End Class
Hope this clears it up.
Chris
"Strahimir Antoljak" <sa*******@langan.com> wrote in message
news:em**************@TK2MSFTNGP10.phx.gbl...
Why can''t I call a public function or sub defined in the main form of my
application from within a module or a class, all being a part of the
same assembly?
When I define public function in a class, I can call it from the form,
but if I define public function in the form and try to call it from the
class it does not work. Any idea what am I doing wrong?
Thanks,
Strah
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!
Hi Chris,
Your input helped. I was creating new instance of the
Windows.System.Forms.Form instead of my form... it helped me to see my
error by looking at your code. Thanks,
Strah
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!
"Strahimir Antoljak" <sa*******@langan.com> schrieb:Why can''t I call a public function or sub defined in the main form of my
application from within a module or a class, all being a part of the
same assembly?
You can do that if you make a refernece to the main form''s instance
available to the module.
Providing a reference to an application''s main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
这篇关于在Form中调用public sub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!