Ejemplo n.º 1
0
        public ShellItemBrowseForm()
        {
            InitializeComponent();

            KnownFolderManager manager = new KnownFolderManager();

            SystemImageList.UseSystemImageList(knownFolderList);
            foreach (KnownFolder knownFolder in manager)
            {
                try
                {
                    ShellItem    shellItem = knownFolder.CreateShellItem();
                    ListViewItem item      = knownFolderList.Items.Add(knownFolder.Name,
                                                                       shellItem.GetSystemImageListIndex(ShellIconType.LargeIcon, 0));

                    item.Tag = knownFolder;

                    if (item.Text == "Personal")
                    {
                        item.Text  = "Personal (My Documents)";
                        item.Group = knownFolderList.Groups["common"];
                    }
                    else if ((item.Text == "Desktop") ||
                             (item.Text == "Downloads") ||
                             (item.Text == "MyComputerFolder"))
                    {
                        item.Group = knownFolderList.Groups["common"];
                    }
                    else
                    {
                        item.Group = knownFolderList.Groups["all"];
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShellTreeView"/> class.
        /// </summary>
        public ShellTreeView()
        {
            m_TreeView               = new TreeView();
            m_TreeView.Dock          = DockStyle.Fill;
            m_TreeView.HideSelection = false;
            m_TreeView.HotTracking   = true;
            m_TreeView.Parent        = this;
            m_TreeView.ShowRootLines = false;
            m_TreeView.AfterSelect  += new TreeViewEventHandler(m_TreeView_AfterSelect);
            m_TreeView.BeforeExpand += new TreeViewCancelEventHandler(m_TreeView_BeforeExpand);
            m_TreeView.ItemDrag     += new ItemDragEventHandler(m_TreeView_ItemDrag);
            m_TreeView.MouseDown    += new MouseEventHandler(m_TreeView_MouseDown);
            m_TreeView.MouseUp      += new MouseEventHandler(m_TreeView_MouseUp);
            m_ScrollTimer.Interval   = 250;
            m_ScrollTimer.Tick      += new EventHandler(m_ScrollTimer_Tick);
            Size = new Size(120, 100);
            SystemImageList.UseSystemImageList(m_TreeView);

            m_ShellListener.DriveAdded     += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.DriveRemoved   += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.FolderCreated  += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.FolderDeleted  += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.FolderRenamed  += new ShellItemChangeEventHandler(m_ShellListener_ItemRenamed);
            m_ShellListener.FolderUpdated  += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.ItemCreated    += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.ItemDeleted    += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.ItemRenamed    += new ShellItemChangeEventHandler(m_ShellListener_ItemRenamed);
            m_ShellListener.ItemUpdated    += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.SharingChanged += new ShellItemEventHandler(m_ShellListener_ItemUpdated);

            // Setting AllowDrop to true then false makes sure OleInitialize()
            // is called for the thread: it must be called before we can use
            // RegisterDragDrop. There is probably a neater way of doing this.
            m_TreeView.AllowDrop = true;
            m_TreeView.AllowDrop = false;

            CreateItems();
        }