Vb.net 通过类访问对象

Vb.net 通过类访问对象,vb.net,Vb.net,在阅读我的一个老项目时,我发现了一些可疑的地方,我不太明白这部分为什么起作用: Public Shared Sub getXMLforProject(QueryString As String) Dim linkStart As String = "http://example.org" Dim linkEnd As String = "&tempMax=2000" Dim target As String = linkStart & QueryStrin

在阅读我的一个老项目时,我发现了一些可疑的地方,我不太明白这部分为什么起作用:

Public Shared Sub getXMLforProject(QueryString As String)
    Dim linkStart As String = "http://example.org"
    Dim linkEnd As String = "&tempMax=2000"
    Dim target As String = linkStart & QueryString & linkEnd

    'replaces parts that need encoding,
    'groups(1) is the sign e.g. <= and groups(2) is the text that needs encoding
    'groups(0) is the text of the full match (sign and encoding text)
    target = rx.Replace(target, Function(m As Match) encodeURLString(m.Groups(1).Value) + encodeURLString(m.Groups(2).Value))

    GUI.WebBrowser.Navigate(target)
    Return True
End Sub

有一个名为GUI的类实现了用户界面,但在文件上下文中没有名为“GUI”的对象可用,因此必须使用该类进行访问。这怎么可能起作用?是否存在将调用从GUI类重定向到GUI对象的隐式机制

如果您使用的是VB.NET,它将模拟早期Visual Basic版本中表单类的行为,在早期版本中,使用类型名称是引用该类实例的合法方式。有点必要给程序员一个战斗的机会来转换他们的VB6项目。底层的管道系统是


因此,99.9%的可能性是GUI类派生自System.Windows.Forms.Form。特别是考虑到它有一个WebBrowser成员。表单是浏览器的主机窗口。

GUI
必须存在于某个位置。如果选择它并按F12,会发生什么情况?通常在visual studio中,它会将您带到声明它的位置。另外,仅供参考-如果您想在类似的情况下替换网址,请尝试使用或-它们的存在正是出于此原因感谢您的提示,请将其替换。Visual Studio实际上引导我找到了类定义它本身,而不是类的对象。它是某种静态/共享类,具有静态/共享
WebBrowser
属性吗?不,bowser声明为:
Public with events WebBrowser as System.Windows.Forms.WebBrowser
,而类声明为
Public class GUI
GUI.WebBrowser.Navigate(target)