2016-05-04 20 views
0

如何從用戶控件訪問公共功能,就像我可以從表單訪問公共功能一樣?公用功能位於公用程序模塊中。在vb.net中,如何從用戶控件中訪問模塊中的公共函數?

+0

這是一個非常愚蠢的問題。我將utility.vb複製到項目中,但分散注意力,並未包含在項目中(右鍵單擊,包含在項目中)。後來我無法弄清楚爲什麼這些功能無處不在。當我回到家時,我記得,但我已經完成了發佈:( – subjectivist

回答

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 
相關問題