我想在 Windows Vista 中隐藏一个目录。只是从视图中没有完全隐藏。就像您从文件夹选项中设置的那样。
我尝试了一些与我看到的例子类似的东西。只是我稍微修改了一下..
这是我的所有代码的组合。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class hideme : Form
{
public hideme()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
if (PasswordTextBox.Text == "test")
{
EnableButton.Visible = true;
DisableButton.Visible = true;
}
else
{
MessageBox.Show("Wrong", "Attention");
Application.Exit();
}
}
private void EnableButton_Click(object sender, EventArgs e)
{
//System.IO.FileInfo dir = new System.IO.FileInfo("C:\\Users\\logickills\\Pictures\\system");
string path = "C:\\Users\\chris\\Pictures\\system";
FileInfo FIh1 = new FileInfo(Environment.CurrentDirectory + @"\Files\File2.txt");
FIh1.Attributes = FileAttributes.Hidden;
}
private void DisableButton_Click(object sender, EventArgs e)
{
}
private void PasswordTextBox_TextChanged(object sender, EventArgs e)
{
}
}
}
这与我之前创建的对话框一致here https://stackoverflow.com/questions/984882/changing-button-attributes-in-c。
输入密码后显示的两个按钮用于显示和隐藏该目录。
Attribute 属性是组合属性,因此您需要将隐藏属性与该项目已有的任何属性结合起来:
FIh1.Attributes = FIh1.Attributes | System.IO.FileAttributes.Hidden;
如果你想删除它,可以使用以下代码:
if ((FIh1.Attributes & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden)
{
FIh1.Attributes = FIh1.Attributes ^ System.IO.FileAttributes.Hidden;
}
如果你打电话FIh1.Attributes = FIh1.Attributes ^ System.IO.FileAttributes.Hidden;
重复地,您将每隔一次打开和关闭隐藏属性。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)