您应该将所有复选框添加到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
您是否想要此版本取决于您是否总是查看所有框,或者您是否只想更新某些框。