所以我正在试着让这个权限应用程序运行起来。我想让字符串adkey作为复选框的名称,就像"cbo“& adkey一样。这样,相同的字符串将成为复选框的名称。我有点生气,把整件事都抄在这里了,所以有点乱。
Dim ADkey As String() =
{"NoChangingWallpaper", "NoHTMlWallpaper"}
' Dim cbo As String =
Dim cho As CheckBox
cho = CType("cbo" & ADkey), CheckBox)
Dim readvalue = My.Computer.Registry.GetValue(
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\ActiveDesktop", ADkey, Nothing)
'MsgBox("The value is " & CStr(readValue))
' Dim cho(ADkey) As CheckBox
cho.Name = ADkey
If readvalue = "1" Then
cho.Checked = True
Else
cho.Checked = False
End Ifmsgbox部分是用于测试的。
发布于 2012-11-02 03:53:45
您应该将所有复选框添加到Dictionary(Of String, Checkbox)对象:
Dim ADkey As String() =
{"NoChangingWallpaper", "NoHTMlWallpaper"}
'This code can move to where the checkboxes are first created, as long as you can reach the variable from here
Dim checkboxes As New Dictionary(Of String, Checkbox) From
{
{"NoChangingWallpaper", cboNoChangingWallpaper},
{"NoHTMlWallpaper", cboNoHTMLWallpaper}
}
For Each key As String in ADKey.Where(Function(k) checkboxes.ContainsKey(k))
Dim regvalue As Boolean = (My.Computer.Registry.GetValue(
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\ActiveDesktop", key, Nothing)="1")
Dim box As Checkbox = checkboxes(key)
box.Name = key
box.Checked = regvalue
Next Key当我看到这一点时,为了避免保留键的重复记录,我可能会完全删除字符串数组,并像这样做:
'This code can move to where the checkboxes are first created, as long as you can reach the variable from here
Dim checkboxes As New Dictionary(Of String, Checkbox) From
{
{"NoChangingWallpaper", cboNoChangingWallpaper},
{"NoHTMlWallpaper", cboNoHTMLWallpaper}
}
For Each key As String in checkboxes.Keys
Dim regvalue As Boolean = (My.Computer.Registry.GetValue(
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\ActiveDesktop", key, Nothing)="1")
Dim box As Checkbox = checkboxes(key)
box.Name = key
box.Checked = regvalue
Next Key你是否想要这个版本取决于你是否总是查看所有的框,或者你可能只想更新某些特定的框。
https://stackoverflow.com/questions/13184378
复制相似问题