我正在使用下面的代码在加载时更改应用程序的标题。我希望能够做到这一点,而不是将它单独放在不同的私有子中,我希望能够将它加载到我的主私有子中,这样我就可以避免两次联系网络服务器。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim wc As WebClient = New WebClient()
Dim Details As String()
Try
Details = wc.DownloadString("http://(IP GOES HERE):8080/launcher/Details.php").Split("#")
wc.Dispose()
Catch ex As Exception
MsgBox("Failed to connect to server. Please make sure you're connected to the internet.", MsgBoxStyle.Critical, "Server Connection Failed")
Return
End Try
Me.Text = Details(7)
End Sub
我在我的主要私有子中使用相同的函数来做另一件事,所以如果我可以把它放在那里,代码会更有效率。