我有一个清单框,其中包含 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]);
}
}
}