实现效果:
知识运用:
RegistryKey类的OpenSubKey方法 //用来检索指定的子项
public RegistryKey OpenSubKey (string name,bool writable) //writable:如果需要项的写访问权限 设为true
实现代码:
private void button2_Click(object sender, EventArgs e) { string path = textBox1.Text; RegistryKey rkey = Registry.CurrentUser; //获取基表 rkey = rkey.OpenSubKey(@"Control Panel\Desktop",true); //检索指定子项 rkey.SetValue("WallPaper",path); rkey.SetValue("TileWallpaper","2"); rkey.Close(); //关闭注册表 MessageBox.Show("设置成功 请重新启动","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); }