⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form2.cs

📁 实现类试于资源管理器的东西
💻 CS
📖 第 1 页 / 共 3 页
字号:
            this.splitter1.Location = new System.Drawing.Point(162, 21);
            this.splitter1.Name = "splitter1";
            this.splitter1.Size = new System.Drawing.Size(4, 390);
            this.splitter1.TabIndex = 7;
            this.splitter1.TabStop = false;
            // 
            // LisrimageList
            // 
            this.LisrimageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
            this.LisrimageList.ImageSize = new System.Drawing.Size(16, 16);
            this.LisrimageList.TransparentColor = System.Drawing.Color.Transparent;
            // 
            // LisrimageList2
            // 
            this.LisrimageList2.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
            this.LisrimageList2.ImageSize = new System.Drawing.Size(16, 16);
            this.LisrimageList2.TransparentColor = System.Drawing.Color.Transparent;
            // 
            // statusBar1
            // 
            this.statusBar1.Location = new System.Drawing.Point(0, 411);
            this.statusBar1.Name = "statusBar1";
            this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
            this.statusBarPanel1,
            this.statusBarPanel2});
            this.statusBar1.Size = new System.Drawing.Size(712, 17);
            this.statusBar1.TabIndex = 8;
            this.statusBar1.Text = "statusBar1";
            // 
            // statusBarPanel1
            // 
            this.statusBarPanel1.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
            this.statusBarPanel1.Name = "statusBarPanel1";
            this.statusBarPanel1.Text = "statusBarPanel1";
            this.statusBarPanel1.Width = 132;
            // 
            // statusBarPanel2
            // 
            this.statusBarPanel2.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
            this.statusBarPanel2.Name = "statusBarPanel2";
            this.statusBarPanel2.Text = "statusBarPanel2";
            this.statusBarPanel2.Width = 132;
            // 
            // menuItem8
            // 
            this.menuItem8.Index = 0;
            this.menuItem8.Text = "关闭";
            this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
            // 
            // Form2
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(712, 428);
            this.Controls.Add(this.listView1);
            this.Controls.Add(this.splitter1);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.statusBar1);
            this.Menu = this.mainMenu1;
            this.Name = "Form2";
            this.Text = "我的资源管理器--2002.9";
            this.panel2.ResumeLayout(false);
            this.panel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion
        /// <summary>
 /// 应用程序的主入口点。
 /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form2());
        }

//*************************************************************************************
 [DllImport("Shell32.dll")] 
 public static extern int ExtractIcon(IntPtr h,string strx,int ii);

 [DllImport("Shell32.dll")] 
 public static extern int SHGetFileInfo(string pszPath,uint dwFileAttributes,ref SHFILEINFO psfi,uint cbFileInfo, uint uFlags);

        public struct SHFILEINFO
        {
            public IntPtr hIcon;
            public int iIcon;
            public uint dwAttributes;
            public char szDisplayName;
            public char szTypeName;
        }
 

 string strFilePath="";
//************************************************************************************* 

        protected virtual Icon myExtractIcon(string FileName, int iIndex)
        {
            try
            {
                IntPtr hIcon = (IntPtr)ExtractIcon(this.Handle, FileName, iIndex);
                if (!hIcon.Equals(null))
                {
                    Icon icon = Icon.FromHandle(hIcon);
                    return icon;
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message, "错误提示", 0, MessageBoxIcon.Error); }
            return null;
        }
//*************************************************************************************

        protected virtual void SetIcon(ImageList imageList, string FileName, bool tf)
        {
            SHFILEINFO fi = new SHFILEINFO();
            if (tf == true)
            {
                int iTotal = (int)SHGetFileInfo(FileName, 0, ref fi, 100, 16640);//SHGFI_ICON|SHGFI_SMALLICON
                try
                {
                    if (iTotal > 0)
                    {
                        Icon ic = Icon.FromHandle(fi.hIcon);
                        imageList.Images.Add(ic);
                        //return ic;
                    }
                }
                catch (Exception ex)
                { MessageBox.Show(ex.Message, "错误提示", 0, MessageBoxIcon.Error); }
            }
            else
            {
                int iTotal = (int)SHGetFileInfo(FileName, 0, ref fi, 100, 257);
                try
                {
                    if (iTotal > 0)
                    {
                        Icon ic = Icon.FromHandle(fi.hIcon);
                        imageList.Images.Add(ic);
                        //return ic;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误提示", 0, MessageBoxIcon.Error);
                }
            }
            // return null;
        }
//*************************************************************************************

        public void GetDrive()
        {
            treeView1.ImageList = TreeImageList;

            treeView1.BeginUpdate();
            treeView1.Nodes.Clear();
           TreeNode RootNode = new TreeNode("文档管理", 4, 4);
            treeView1.Nodes.Add(RootNode);

            //int iImageIndex = 4;
            //int iSelectedIndex = 4;
           // string[] astrDrives = Directory.GetLogicalDrives();
            string[] astrDrives = Directory.GetDirectories("E:\\", "音乐", System.IO.SearchOption.TopDirectoryOnly);
               
            foreach (string str in astrDrives)
            {
                TreeNode tnDrive = new TreeNode(str,4,4);
                
               // treeView1.Nodes[0].Nodes.Add(tnDrive);
                //AddDirectories(tnDrive);

                if (str == "E:\\音乐")
                {
                   treeView1.SelectedNode = tnDrive;
                }
                treeView1.Nodes[0].Nodes.Add(tnDrive);
               
            }
            treeView1.EndUpdate();
           
        }


//*************************************************************************************

        void AddDirectories(TreeNode tn)
        {
            tn.Nodes.Clear();

            string strPath = tn.FullPath;
            strPath = strPath.Remove(0, 5);

            //获得当前目录
            DirectoryInfo dirinfo = new DirectoryInfo(strPath);
            DirectoryInfo[] adirinfo;
            try
            {
                adirinfo = dirinfo.GetDirectories();
            }
            catch
            { return; }

            int iImageIndex = 4; int iSelectedIndex = 5;
            foreach (DirectoryInfo di in adirinfo)
            {
                if (di.Name == "RECYCLER" || di.Name == "RECYCLED" || di.Name == "Recycled")
                { iImageIndex = 6; iSelectedIndex = 6; }
                else
                { iImageIndex = 4; iSelectedIndex = 5; }

                TreeNode tnDir = new TreeNode(di.Name, iImageIndex, iSelectedIndex);
                tn.Nodes.Add(tnDir);
            }


          //  /*
               //获得当前目录下的所有文件 
               FileInfo[] dirFiles;
               //如果GetFiles()属性设置为空者返回所有文件
               dirFiles = dirinfo.GetFiles("*.");
               int iCount=7;

               foreach (FileInfo fi in dirFiles)
               {
                   //得到每个文件的图标
                   string str = fi.FullName;
                   try
                   {
                       SetIcon(TreeImageList, str, false);
                   }
                   catch (Exception ex)
                   { MessageBox.Show(ex.Message, "错误提示", 0, MessageBoxIcon.Error); }

                   TreeNode tnDir = new TreeNode(fi.Name, iCount, iCount);
                   tn.Nodes.Add(tnDir);

                   iCount++;
               }
           // */
        }
//*************************************************************************************
 //在大图标、小图标、详细列表切换时调用
        protected virtual void ListViewAB(int iii)
        {
            if (iii == 1)
            {
                LisrimageList2.ImageSize = new Size(32, 32);
                listView1.LargeImageList = LisrimageList2;

                if (listView1.View == View.Details || listView1.View == View.SmallIcon)
                { listView1.View = View.LargeIcon; }
            }
            else if (iii == 2)
            {
                if (listView1.View == View.Details || listView1.View == View.LargeIcon)
                { listView1.View = View.SmallIcon; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -