0

所以我试图让这个权限应用程序运行起来。我被困在我想让字符串 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 If

msgbox 部分用于测试

4

1 回答 1

1

您应该将所有复选框添加到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

您是否想要此版本取决于您是否总是查看所有框,或者您是否只想更新某些框。

于 2012-11-01T19:53:44.977 回答