在vb.net中,如何从用户控件中访问模块中的公共函数?

时间:2016-05-04 21:06:13

标签: vb.net visual-studio

如何从用户控件访问公共函数的方式与从表单访问公共函数的方式相同?公共功能位于实用程序模块中。

1 个答案:

答案 0 :(得分:1)

假设您有一个名为SpecialUtility的模块位于SomeProject.Utilities名称空间中。

' Without "Global." prefix the "SomeProject.Utilities" namespace 
' would be placed under the project's default namespace.
' If your project's default namespace was "SomeProject" then 
' you could write only "Namespace Utilities" in this case.
Namespace Global.SomeProject.Utilities
    Module SpecialUtility
        Public Sub DoSomething()
            Console.WriteLine("Doing something")
        End Sub
    End Module
End Namespace

您应该在用户控件中导入该实用程序模块的命名空间。

Imports SomeProject.Utilities

Public Class SomeUserControl
    Private Sub SomeAction()
        ' Now you can call DoSomething() method from SpecialUtility module.
        DoSomething()
    End Sub
End Class