Inheritance: System.Windows.Forms.TreeView
        /// <summary>
        /// Initializes a new instance of the <see cref="ShellTreeView"/> class.
        /// </summary>
        public ShellTreeView()
        {
            m_TreeView               = new TreeViewBase();
            m_TreeView.Dock          = DockStyle.Fill;
            m_TreeView.BackColor     = Color.White;
            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_TreeView.BorderStyle   = BorderStyle.None;
            m_ScrollTimer.Interval   = 250;
            m_ScrollTimer.Tick      += new EventHandler(m_ScrollTimer_Tick);
            Size = new System.Drawing.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;
            this.DoubleBuffered  = true;
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
            CreateItems();
        }
Exemplo n.º 2
0
		private void InitTreeView() {
			this.AllowDrop = true;
			this.ShellTreeView = new TreeViewBase();
			this.ShellTreeView.Dock = DockStyle.Fill;
			this.ShellTreeView.BackColor = Color.White;
			this.ShellTreeView.BorderStyle = F.BorderStyle.None;
			this.ShellTreeView.AllowDrop = true;
			this.ShellTreeView.HideSelection = false;
			this.ShellTreeView.ShowLines = false;
			this.ShellTreeView.HotTracking = true;
			this.ShellTreeView.LabelEdit = true;
			this.ShellTreeView.DrawMode = TreeViewDrawMode.OwnerDrawAll;
			this.ShellTreeView.DrawNode += ShellTreeView_DrawNode;
			this.ShellTreeView.BeforeExpand += ShellTreeView_BeforeExpand;
			this.ShellTreeView.AfterExpand += ShellTreeView_AfterExpand;
			this.ShellTreeView.MouseDown += ShellTreeView_MouseDown;
			this.ShellTreeView.HandleDestroyed += ShellTreeView_HandleDestroyed;
			this.ShellTreeView.ItemDrag += ShellTreeView_ItemDrag;
			this.ShellTreeView.AfterSelect += ShellTreeView_AfterSelect;
			this.ShellTreeView.NodeMouseClick += ShellTreeView_NodeMouseClick;
			this.ShellTreeView.AfterLabelEdit += ShellTreeView_AfterLabelEdit;
			this.ShellTreeView.KeyDown += ShellTreeView_KeyDown;
			this.ShellTreeView.DragEnter += ShellTreeView_DragEnter;
			this.ShellTreeView.DragOver += ShellTreeView_DragOver;
			this.ShellTreeView.DragLeave += ShellTreeView_DragLeave;
			this.ShellTreeView.DragDrop += ShellTreeView_DragDrop;
			this.ShellTreeView.GiveFeedback += ShellTreeView_GiveFeedback;
			this.ShellTreeView.MouseMove += ShellListView_MouseMove;
			this.ShellTreeView.MouseEnter += ShellTreeView_MouseEnter;
			this.ShellTreeView.MouseLeave += ShellTreeView_MouseLeave;
			//this.ShellTreeView.MouseWheel += ShellTreeView_MouseWheel;
			//this.ShellTreeView.VerticalScroll += ShellTreeView_VerticalScroll;
			//this.ShellTreeView.BeforeSelect += ShellTreeView_BeforeSelect;
			if (this.ShellListView != null) {
				this.ShellListView.Navigated += ShellListView_Navigated;
			}
			SystemImageList.UseSystemImageList(ShellTreeView);
			ShellTreeView.FullRowSelect = true;
			var defIconInfo = new Shell32.SHSTOCKICONINFO() { cbSize = (uint)Marshal.SizeOf(typeof(Shell32.SHSTOCKICONINFO)) };
			Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_FOLDER, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo);
			this.folderImageListIndex = defIconInfo.iSysIconIndex;
			imagesThread = new Thread(new ThreadStart(LoadTreeImages)) { IsBackground = true };
			imagesThread.SetApartmentState(ApartmentState.STA);
			imagesThread.Start();
			childsThread = new Thread(new ThreadStart(LoadChilds)) { IsBackground = true };
			childsThread.Start();
		}