-1

很抱歉标题不好,因为我不知道如何调用标题我想保存文本框值,如果它是一个整数到名称为 IP 的配置文件,如果它是一个字符串到名称 DNS 这是代码 :

Public Class ServerSettings

Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
    If IPHostInfo.Text = "" Then ' here if it's a string save it to my.settings.dns
        My.Settings.DNS() = IPHostInfo.Text

    Else : IPHostInfo.Text = ""
        My.Settings.IP() = IPHostInfo.Text 'and if it's an integer
    End If
    My.Settings.PORT() = IPInfo.Text
    My.Settings.TOut() = TOut.Text
    IPHostInfo.Text = IPHostInfo.Text
    IPInfo.Text = IPInfo.Text
    TOut.Text = TOut.Text
    Me.DialogResult = System.Windows.Forms.DialogResult.OK
    Me.Close()
End Sub

Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
    Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
    Me.Close()
End Sub

结束类

4

1 回答 1

0

如果您需要确定字符串是否是有效的 IP 地址,我认为最简单的方法是简单地调用IPAddress.TryParse,例如:

If IPAddress.TryParse(IPHostInfo.Text, Nothing) Then
    ' It's an IP Address
    My.Settings.IP() = IPHostInfo.Text
Else
    ' It's not an IP Address, so it must be a DNS name
    My.Settings.DNS() = IPHostInfo.Text
End If
于 2012-09-12T13:13:16.930 回答