【发布时间】:2016-11-25 10:58:48
【问题描述】:
我目前正在 C# Winform 中制作闪存驱动器锁(它隐藏/取消隐藏文件夹)。
我已经准备好把它做成 C# 控制台,所以我有大部分需要的命令。我有一个 dir 命令获取所有文件夹的路径
public static dynamic getFolder()
{
Dictionary<dynamic, List<dynamic>> dictionary = new Dictionary<dynamic, List<dynamic>>();
int selector = 1;
bool isHidden;
foreach (string folderPath in Directory.GetDirectories(Form2.driveLetter))
{
List<dynamic> data = new List<dynamic>();
string folderName = folderPath.Substring(3);
if (folderName == "#") { continue; }
if (folderName == "System Volume Information") { continue; }
isHidden = Status(folderPath);
data.Add(folderPath.Substring(3, folderPath.Length - 3));
data.Add(isHidden);
data.Add(folderPath);
dictionary.Add(selector, data);
selector++;
}
dictionary.Add(selector++, Vault());
return dictionary;
}
then I have the Dictionary piped into a different method that gets the names of the folder(and hidden state) then turns them into checked boxes; if the folder is hidden, then the box is checked, and if it isn't, then its unhidden (I will in time make this part more efficient)
然后我将 Dictionary 导入另一种获取文件夹名称(和隐藏状态)的方法,然后将它们转换为复选框;如果文件夹被隐藏,则选中该框,如果不是,则取消隐藏(我会及时使这部分更有效)
private void CreateBox(Dictionary<dynamic, List<dynamic>> dictionary)
{
int y = 0;
int z = 0;
CheckBox box;
for (int x = 1; x < dictionary.Count(); x++)
{
List<dynamic> folder = dictionary[x];
box = new CheckBox();
box.Text = folder[0];
box.AutoSize = true;
box.Checked = folder[1];
if (y == 180)
{
box.Location = new Point(370, 39 + z);
z += 20;
}
else
{
box.Location = new Point(198, 39 + y);
y += 20;
}
this.Controls.Add(box);
CheckBoxes.Add(box);
}
}
How do I link a SetAttributes command to the check box, so when the box is checked, it hides the respective folder and when the box is unchecked, it unhides the folder
【问题讨论】:
-
请不要链接到外部网站。
-
您的问题是否只是询问如何将事件处理程序附加到动态创建的控件?
-
听起来不错,我正在尝试将命令链接到取消/选中特定框的时间。因此,当音乐标签旁边的框未选中时,它会在 E:\Music 处触发取消隐藏命令,如果再次选中,它将在 E:\Music 处触发隐藏命令
-
我对在此处设置复选框时如何操作有所了解,但在动态制作时我不知道如何操作。
标签: c# winforms checkbox dynamic