使用复选框列表更新注册表

本文关键字:更新 注册表 列表 复选框 | 更新日期: 2023-09-27 18:35:42

我有一个清单框,其中包含 5 个目录,我的程序稍后将调用这些目录。我希望用户能够通过复选框检查他们想要使用的目录。到目前为止,他们可以选择他们想要的每个项目,它将被添加,但我希望从注册表中删除未选中的框

private void button1_Click(object sender, EventArgs e)
{
    textBox1.Text = "";
    foreach (object checkbox in checkedListBox1.CheckedItems)
    {
        textBox1.AppendText("Item is marked: " + checkbox.ToString() + "'n");
        RegBUP.SetValue(checkbox);
    }
}

因此,人们对我在做什么有一个更大致的想法:catchpath() 返回目录中的路径,因此如果它到达桌面,它会返回桌面的路径。

public static void SetValue(object title)
{
    RegistryKey directs = regKey.OpenSubKey("Path to registry", true);
    directs.SetValue(title.ToString(), catchpath(title), RegistryValueKind.String);
    directs.Close();
}

使用复选框列表更新注册表

// you can try this
    private void button1_Click(object sender, EventArgs e)
    {
        textBox1.Text = "";
                 for (int i = 0; i < checkedListBox1.Items.Count; i++)
                        {
                           if (checkedListBox1.GetItemChecked(i) == true)
                            {
                           textBox1.AppendText("Item is marked: " +checkedListBox1.Items[i].ToString()+ "'n");
                              RegBUP.SetValue(checkedListBox1.Items[i]);
                            }
                           else
                             {
                                 RegBUP.DeleteValue(checkedListBox1.Items[i]);
                             }
                        }
    }