private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e) { SEItem item = (SEItem)e.Node.Tag; Brush b = Brushes.Black; if (item.isConsole) { b = Brushes.Blue; } if (!item.Enabled) { b = Brushes.Gray; } else { TreeNode parent = e.Node.Parent; while (parent != null) { if (!parent.Checked) { b = Brushes.Gray; break; } parent = parent.Parent; } } Rectangle frame = e.Bounds; if ((e.State & TreeNodeStates.Selected) != 0) { frame.Width = (int)e.Graphics.MeasureString(item.ToString(), treeView1.Font).Width; e.Graphics.FillRectangle(TreeViewBackBrush, frame); frame.Inflate(-1, -1); e.Graphics.DrawRectangle(Pens.Red, frame); } if (item.isSeparator) { e.Graphics.DrawLine(Pens.Black, frame.Left + 4, frame.Top + frame.Height / 2, frame.Right - 4, frame.Top + frame.Height / 2); } else { e.Graphics.DrawString(item.ToString(), treeView1.Font, b, e.Bounds.Left, e.Bounds.Top + 2); } }
public void ReadShellExtensions(string path) { int iterator = 0; ArrayList dirList = new ArrayList(); ArrayList itemsList = new ArrayList(); dirList.Add(path); while (iterator < dirList.Count) { foreach (string dir in Directory.GetDirectories(dirList[iterator].ToString())) { dirList.Add(dir); itemsList.Add(dir); } foreach (string file in Directory.GetFiles(dirList[iterator].ToString(), "*.cmd*")) itemsList.Add(file); foreach (string file in Directory.GetFiles(dirList[iterator].ToString(), "*.separator")) itemsList.Add(file); iterator++; } //sort according the ShellExtension sorting algorithm itemsList.Sort(Sorter.instance); //foreach (string item in itemsList) // Trace.WriteLine(item); TreeNode dirNode = null; foreach (string item in itemsList) { SEItem shellEx = new SEItem(item); TreeNode node = new TreeNode(shellEx.ToString()); node.Checked = shellEx.Enabled; node.Tag = shellEx; if (dirNode == null) { treeView1.Nodes.Add(node); } else { TreeNode parentNode = dirNode; SEItem parentShellEx = null; do { parentShellEx = (parentNode.Tag as SEItem); if (parentShellEx == null) { treeView1.Nodes.Add(node); } else if (parentShellEx.level == shellEx.level - 1) { parentNode.Nodes.Add(node); break; } parentNode = parentNode.Parent; } while (parentNode != null); if (parentNode == null) treeView1.Nodes.Add(node); } if (shellEx.isDir) dirNode = node; } treeView1.ExpandAll(); }
public void ReadShellExtensions(string path) { int iterator = 0; ArrayList dirList = new ArrayList(); ArrayList itemsList = new ArrayList(); dirList.Add(path); while (iterator < dirList.Count) { foreach (string dir in Directory.GetDirectories(dirList[iterator].ToString())) { dirList.Add(dir); itemsList.Add(dir); } foreach (string file in Directory.GetFiles(dirList[iterator].ToString(), "*.cmd*")) { itemsList.Add(file); } foreach (string file in Directory.GetFiles(dirList[iterator].ToString(), "*.separator")) { itemsList.Add(file); } iterator++; } //sort according the ShellExtension sorting algorithm itemsList.Sort(Sorter.instance); //foreach (string item in itemsList) // Trace.WriteLine(item); TreeNode dirNode = null; foreach (string item in itemsList) { SEItem shellEx = new SEItem(item); TreeNode node = new TreeNode(shellEx.ToString()); node.Checked = shellEx.Enabled; node.Tag = shellEx; if (dirNode == null) { treeView1.Nodes.Add(node); } else { TreeNode parentNode = dirNode; SEItem parentShellEx = null; do { parentShellEx = (parentNode.Tag as SEItem); if (parentShellEx == null) { treeView1.Nodes.Add(node); } else if (parentShellEx.level == shellEx.level - 1) { parentNode.Nodes.Add(node); break; } parentNode = parentNode.Parent; } while (parentNode != null); if (parentNode == null) { treeView1.Nodes.Add(node); } } if (shellEx.isDir) { dirNode = node; } } treeView1.ExpandAll(); }