我试图在 VB.NET 的模块中使用 MY 命名空间,但它说“我的未声明...”使用 MY 命名空间会节省很多时间,但是我可以在模块中使用它吗?
Imports System.Windows.Forms
Public Module Entry_Module
Sub Main()
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\Currentversion\Run\", "MyApp", application.executeablepath, RegistryValueKind.String)
End Sub
End Module
我正在将我的应用程序添加到启动中,我的应用程序没有表单而是模块。那么如何在这个模块中使用我的命名空间?
最佳答案
您必须使用 My
方法中的命名空间才能可用,我认为这是您的问题。看:
Public Class MyClass
My.<Does not work>
Public Sub MyMethod()
My.<Correct>
End Sub
End Class
无论如何,如果你想在任何地方使用它,你可以创建一个新类来检索你想要的信息:
Public Class MyNS
Public Shared Function CurrentDirectory() As String
Return My.Computer.FileSystem.CurrentDirectory()
End Function
'etc
End Class
然后在调用类方法的任何地方使用它:
MyNS.CurrentDirectory()
额外信息 :
My
namespace and project types .
关于vb.net - 在模块中使用我的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15117034/