0

我正在尝试将所有保存的 my.settings 加载到我的文本框中,但我无法检索保存的值。这是我的代码

Dim ctrl As Control
    For Each ctrl In Me.Controls
        If (ctrl.GetType() Is GetType(TextBox)) Then
            Dim txt As TextBox = CType(ctrl, TextBox)
            For i As Integer = 1 To 20
                txt.Text = My.Settings("fp" & i)
            Next
        End If
    Next

正确的方法是什么?谢谢

4

1 回答 1

0

通常,当您引用存储在设置中的值时,它将沿着 ;

My.Settings.<name of the setting>

My.Settings 有一个 Item 属性,它将 Settings PropertyName(作为字符串)作为参数,允许您设置或获取相关值。

因此,首先尝试以下方法;

Dim ctrl As Control
    For Each ctrl In Me.Controls
        If (ctrl.GetType() Is GetType(TextBox)) Then
            Dim txt As TextBox = CType(ctrl, TextBox)
            For i As Integer = 1 To 20
                txt.Text = My.Settings.Item("fp" & i.ToString)
            Next
        End If
    Next
于 2016-01-21T07:30:17.360 回答