首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vb 2010复选框循环

vb 2010复选框循环
EN

Stack Overflow用户
提问于 2012-11-02 03:45:44
回答 1查看 350关注 0票数 0

所以我正在试着让这个权限应用程序运行起来。我想让字符串adkey作为复选框的名称,就像"cbo“& adkey一样。这样,相同的字符串将成为复选框的名称。我有点生气,把整件事都抄在这里了,所以有点乱。

代码语言:javascript
复制
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部分是用于测试的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-02 03:53:45

您应该将所有复选框添加到Dictionary(Of String, Checkbox)对象:

代码语言:javascript
复制
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

当我看到这一点时,为了避免保留键的重复记录,我可能会完全删除字符串数组,并像这样做:

代码语言:javascript
复制
'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

你是否想要这个版本取决于你是否总是查看所有的框,或者你可能只想更新某些特定的框。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13184378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档