实现效果:
知识运用:
FileInfo类的Attribute属性 //获取或设置文件的属性
public FileAttributes Attributes {get; set;}
实现代码:
private void button1_Click(object sender, EventArgs e) { System.IO.FileInfo file=new System.IO.FileInfo(textBox1.Text); if (checkBox1.Checked == true) { file.Attributes = System.IO.FileAttributes.ReadOnly; }else if (checkBox2.Checked == true){ file.Attributes = System.IO.FileAttributes.System; }else if (checkBox3.Checked == true){ file.Attributes = System.IO.FileAttributes.Archive; }else if (checkBox4.Checked == true){ file.Attributes = System.IO.FileAttributes.Hidden; } }