0

我正在使用下面的代码在加载时更改应用程序的标题。我希望能够做到这一点,而不是将它单独放在不同的私有子中,我希望能够将它加载到我的主私有子中,这样我就可以避免两次联系网络服务器。

    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

我在我的主要私有子中使用相同的函数来做另一件事,所以如果我可以把它放在那里,代码会更有效率。

4

1 回答 1

0
Dim CommDetails As String()

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim wc As WebClient = New WebClient()

    Try
        CommDetails = 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 = CommDetails(7)

End Sub

在您的另一个子中:

    some_text = CommDetails(7)
于 2013-04-10T12:07:28.897 回答