Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用复选框列表更新注册表?_C#_Checkbox_Foreach_Registrykey - Fatal编程技术网

C# 使用复选框列表更新注册表?

C# 使用复选框列表更新注册表?,c#,checkbox,foreach,registrykey,C#,Checkbox,Foreach,Registrykey,我有一个复选框,其中有5个目录,我的程序稍后将调用。我希望用户能够通过一个复选框来检查他们想要使用的目录。到目前为止,他们可以选择他们想要的每个项目,它将被添加,但我希望取消选中的框从注册表中删除 private void button1_Click(object sender, EventArgs e) { textBox1.Text = ""; foreach (object checkbox in checkedListBox1.CheckedItems) {

我有一个复选框,其中有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();
}
//您可以试试这个
私有无效按钮1\u单击(对象发送者,事件参数e)
{
textBox1.Text=“”;
对于(int i=0;i
您的所有用户都有注册表修改权限吗?是,但只能访问当前用户和目录子项。我将值存储在HKCU/software/myprogram/目录值中。他们只能更改5个键以启用/禁用程序执行的操作。您可以在注册表中设置所有5个键,并根据复选框状态将值设置为0或1(如果有帮助)。我在问题中添加了更多内容,该值是指向目录的路径。如果您正在查找,则可以使用DeleteValue方法。我还没有尝试过它,但读取它时,它看起来与我想要的完全一样。
// 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]);
                             }
                        }
    }