Exemplo n.º 1
0
        internal void Init()
        {
            this.BeforeExpand += NativeTreeView_BeforeExpand;

            SetWindowTheme(this.Handle, "explorer", null);
            if (!this.ImageList.Images.ContainsKey("FolderIcon"))
            {
                this.ImageList.Images.Add("FolderIcon", ShellIcon.GetLargeFolderIcon());
                this.ImageList.Images.Add("LockFolder", ShellIcon.GetIconFromIndex("shell32.dll", 47));
                /// Detect icon base on Windows version
                var vs = Environment.OSVersion;
                switch (vs.Version.Major)
                {
                /// Windows vista, 7, 8, 8.1
                case 6:
                    this.ImageList.Images.Add("ComputerIcon", ShellIcon.GetIconFromIndex("shell32.dll", 15));
                    this.ImageList.Images.Add("LibrariesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 202));
                    this.ImageList.Images.Add("FavoritesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 203));
                    break;

                /// Windows 10
                case 10:
                    this.ImageList.Images.Add("ComputerIcon", ShellIcon.GetIconFromIndex("shell32.dll", 15));
                    this.ImageList.Images.Add("LibrariesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 203));
                    this.ImageList.Images.Add("FavoritesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 200));
                    break;

                default:
                    throw new NotSupportedException("This windows version is not supported");
                }
            }

            this.HideSelection = false;
            // FullRowSelect is ignored if ShowLines is set to true.
            this.ShowLines     = false;
            this.FullRowSelect = true;

            AddFavorites();
            AddLibraries();
            AddComputer();

            // change items height
            int nodeHeight = this.Nodes[0].Bounds.Height;

            this.ItemHeight = nodeHeight + 4;
        }