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

📄 form1.cs

📁 。net的资源管理器
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;

namespace myTree
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ImageList TreeImageList;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TreeView treeView1;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.ImageList LisrimageList;
		private System.Windows.Forms.ImageList LisrimageList2;
		private System.Windows.Forms.StatusBar statusBar1;
		private System.Windows.Forms.StatusBarPanel statusBarPanel1;
		private System.Windows.Forms.StatusBarPanel statusBarPanel2;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.MenuItem menuItem5;
		private System.Windows.Forms.MenuItem menuItem6;
		private System.Windows.Forms.MenuItem menuItem7;
		private System.Windows.Forms.Label label1;
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			Icon ic0=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",15);
			TreeImageList.Images.Add(ic0);
			Icon ic1=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",5);
			TreeImageList.Images.Add(ic1);
			Icon ic2=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",7);
			TreeImageList.Images.Add(ic2);
			Icon ic3=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",11);
			TreeImageList.Images.Add(ic3);

			Icon ic4=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",3);
			TreeImageList.Images.Add(ic4);
			Icon ic5=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",4);
			TreeImageList.Images.Add(ic5);
			Icon ic6=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",101);
			TreeImageList.Images.Add(ic6);


			GetDrive();
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.TreeImageList = new System.Windows.Forms.ImageList(this.components);
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.menuItem5 = new System.Windows.Forms.MenuItem();
			this.menuItem6 = new System.Windows.Forms.MenuItem();
			this.menuItem7 = new System.Windows.Forms.MenuItem();
			this.listView1 = new System.Windows.Forms.ListView();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.treeView1 = new System.Windows.Forms.TreeView();
			this.panel2 = new System.Windows.Forms.Panel();
			this.label1 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.panel1 = new System.Windows.Forms.Panel();
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.LisrimageList = new System.Windows.Forms.ImageList(this.components);
			this.LisrimageList2 = new System.Windows.Forms.ImageList(this.components);
			this.statusBar1 = new System.Windows.Forms.StatusBar();
			this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
			this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
			this.panel2.SuspendLayout();
			this.panel1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
			this.SuspendLayout();
			//
			// TreeImageList
			//
			this.TreeImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.TreeImageList.ImageSize = new System.Drawing.Size(16, 16);
			this.TreeImageList.TransparentColor = System.Drawing.Color.Transparent;
			//
			// mainMenu1
			//
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem1,
																					  this.menuItem2,
																					  this.menuItem3,
																					  this.menuItem4});
			//
			// menuItem1
			//
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "文件";
			//
			// menuItem2
			//
			this.menuItem2.Index = 1;
			this.menuItem2.Text = "编辑";
			//
			// menuItem3
			//
			this.menuItem3.Index = 2;
			this.menuItem3.Text = "显隐";
			this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
			//
			// menuItem4
			//
			this.menuItem4.Index = 3;
			this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem5,
																					  this.menuItem6,
																					  this.menuItem7});
			this.menuItem4.Text = "列表方式";
			//
			// menuItem5
			//
			this.menuItem5.Index = 0;
			this.menuItem5.Text = "大图标";
			this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
			//
			// menuItem6
			//
			this.menuItem6.Index = 1;
			this.menuItem6.Text = "小图标";
			this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
			//
			// menuItem7
			//
			this.menuItem7.Index = 2;
			this.menuItem7.Text = "详细列表";
			this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
			//
			// listView1
			//
			this.listView1.Activation = System.Windows.Forms.ItemActivation.OneClick;
			this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.listView1.Location = new System.Drawing.Point(221, 25);
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(491, 381);
			this.listView1.TabIndex = 3;
			this.listView1.View = System.Windows.Forms.View.SmallIcon;
			this.listView1.ItemActivate += new System.EventHandler(this.listView1_ItemActivate);
			//
			// textBox1
			//
			this.textBox1.Dock = System.Windows.Forms.DockStyle.Top;
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(712, 25);
			this.textBox1.TabIndex = 5;
			this.textBox1.Text = "";
			//
			// treeView1
			//
			this.treeView1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
				| System.Windows.Forms.AnchorStyles.Left)
				| System.Windows.Forms.AnchorStyles.Right);
			this.treeView1.ImageIndex = -1;
			this.treeView1.ItemHeight = 18;
			this.treeView1.Location = new System.Drawing.Point(0, 29);
			this.treeView1.Name = "treeView1";
			this.treeView1.SelectedImageIndex = -1;
			this.treeView1.Size = new System.Drawing.Size(216, 349);
			this.treeView1.TabIndex = 1;
			this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect_1);
			this.treeView1.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeView1_BeforeExpand_1);
			//
			// panel2
			//
			this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.label1,
																				 this.button1});
			this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(216, 28);
			this.panel2.TabIndex = 0;
			//
			// label1
			//
			this.label1.Dock = System.Windows.Forms.DockStyle.Left;
			this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 24);
			this.label1.TabIndex = 1;
			this.label1.Text = "文件夹";
			this.label1.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
			//
			// button1
			//
			this.button1.Dock = System.Windows.Forms.DockStyle.Right;
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button1.Location = new System.Drawing.Point(188, 0);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(24, 24);
			this.button1.TabIndex = 0;
			this.button1.Text = "X";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			//
			// panel1
			//
			this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.treeView1,
																				 this.panel2});
			this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
			this.panel1.Location = new System.Drawing.Point(0, 25);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(216, 381);
			this.panel1.TabIndex = 6;
			//
			// splitter1
			//
			this.splitter1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.splitter1.Location = new System.Drawing.Point(216, 25);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(5, 381);
			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, 406);
			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, 22);
			this.statusBar1.TabIndex = 8;
			this.statusBar1.Text = "statusBar1";
			//
			// statusBarPanel1
			//
			this.statusBarPanel1.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
			this.statusBarPanel1.Text = "statusBarPanel1";
			this.statusBarPanel1.Width = 132;
			//
			// statusBarPanel2
			//
			this.statusBarPanel2.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
			this.statusBarPanel2.Text = "statusBarPanel2";
			this.statusBarPanel2.Width = 132;
			//
			// Form1
			//
			this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
			this.ClientSize = new System.Drawing.Size(712, 428);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.listView1,
																		  this.splitter1,
																		  this.panel1,
																		  this.textBox1,
																		  this.statusBar1});
			this.Menu = this.mainMenu1;
			this.Name = "Form1";
			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);

		}
		#endregion

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

		//*************************************************************************************
		[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;
					}

⌨️ 快捷键说明

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