📄 filemanager.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace FileManager
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtCurPath;
private System.Windows.Forms.Button btnUp;
private System.Windows.Forms.ListView FilesView;
private System.Windows.Forms.ImageList imageLarge;
private System.Windows.Forms.ImageList imageSmall;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem NewFolder;
private System.Windows.Forms.MenuItem NewFile;
private System.Windows.Forms.MenuItem ExitMenu;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem ContextmenuItemNew;
private System.Windows.Forms.MenuItem ContextmenuItemDelete;
private System.Windows.Forms.MenuItem ContextmenuItemFolder;
private System.Windows.Forms.MenuItem ContextmenuItemFile;
private System.Windows.Forms.MenuItem Delete;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.MenuItem ContextmenuItemFresh;
//CurPath集合属性存储了每一级目录的全路径
System.Collections.Specialized.StringCollection CurPath = new System.Collections.Specialized.StringCollection();
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
try
{
//初始路径为My Computer
this.txtCurPath.Text = "My Computer";
//清空FilesView控件
this.FilesView.Clear();
this.FilesView.View = View.Details;
this.FilesView.Columns.Add("本地磁盘",FilesView.Width/3,HorizontalAlignment.Left);
string[] Drv = Directory.GetLogicalDrives();
int DrvCnt = Drv.Length;
for(int i = 0;i<DrvCnt;i++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = "驱动器" + Drv[i];
lvi.ImageIndex = 3;
lvi.Tag = Drv[i];
this.FilesView.Items.Add(lvi);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.NewFolder = new System.Windows.Forms.MenuItem();
this.NewFile = new System.Windows.Forms.MenuItem();
this.ExitMenu = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.Delete = new System.Windows.Forms.MenuItem();
this.label1 = new System.Windows.Forms.Label();
this.txtCurPath = new System.Windows.Forms.TextBox();
this.btnUp = new System.Windows.Forms.Button();
this.FilesView = new System.Windows.Forms.ListView();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.ContextmenuItemNew = new System.Windows.Forms.MenuItem();
this.ContextmenuItemFolder = new System.Windows.Forms.MenuItem();
this.ContextmenuItemFile = new System.Windows.Forms.MenuItem();
this.ContextmenuItemDelete = new System.Windows.Forms.MenuItem();
this.imageLarge = new System.Windows.Forms.ImageList(this.components);
this.imageSmall = new System.Windows.Forms.ImageList(this.components);
this.ContextmenuItemFresh = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem3});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.ExitMenu});
this.menuItem1.Text = "文件(&F)";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.NewFolder,
this.NewFile});
this.menuItem2.Text = "新建(&N)";
//
// NewFolder
//
this.NewFolder.Index = 0;
this.NewFolder.Text = "文件夹(&J)";
this.NewFolder.Click += new System.EventHandler(this.NewFolder_Click);
//
// NewFile
//
this.NewFile.Index = 1;
this.NewFile.Text = "文件(&W)";
this.NewFile.Click += new System.EventHandler(this.NewFile_Click);
//
// ExitMenu
//
this.ExitMenu.Index = 1;
this.ExitMenu.Text = "退出(&X)";
this.ExitMenu.Click += new System.EventHandler(this.ExitMenu_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.Delete});
this.menuItem3.Text = "编辑&E";
//
// Delete
//
this.Delete.Index = 0;
this.Delete.Text = "删除&D";
this.Delete.Click += new System.EventHandler(this.Delete_Click);
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(24, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 24);
this.label1.TabIndex = 0;
this.label1.Text = "当前路径:";
this.label1.TextAlign = System.Drawing.ContentAlignment.BottomRight;
//
// txtCurPath
//
this.txtCurPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtCurPath.Location = new System.Drawing.Point(112, 10);
this.txtCurPath.Name = "txtCurPath";
this.txtCurPath.Size = new System.Drawing.Size(152, 21);
this.txtCurPath.TabIndex = 1;
this.txtCurPath.Text = "";
//
// btnUp
//
this.btnUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnUp.Location = new System.Drawing.Point(280, 8);
this.btnUp.Name = "btnUp";
this.btnUp.Size = new System.Drawing.Size(96, 24);
this.btnUp.TabIndex = 2;
this.btnUp.Text = "返回上级目录";
this.btnUp.Click += new System.EventHandler(this.btnUp_Click);
//
// FilesView
//
this.FilesView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.FilesView.ContextMenu = this.contextMenu1;
this.FilesView.LargeImageList = this.imageLarge;
this.FilesView.Location = new System.Drawing.Point(8, 48);
this.FilesView.Name = "FilesView";
this.FilesView.Size = new System.Drawing.Size(376, 200);
this.FilesView.SmallImageList = this.imageSmall;
this.FilesView.TabIndex = 3;
this.FilesView.View = System.Windows.Forms.View.Details;
this.FilesView.DoubleClick += new System.EventHandler(this.FilesView_DoubleClick);
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.ContextmenuItemNew,
this.ContextmenuItemDelete,
this.ContextmenuItemFresh});
//
// ContextmenuItemNew
//
this.ContextmenuItemNew.Index = 0;
this.ContextmenuItemNew.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.ContextmenuItemFolder,
this.ContextmenuItemFile});
this.ContextmenuItemNew.Text = "新建&N";
//
// ContextmenuItemFolder
//
this.ContextmenuItemFolder.Index = 0;
this.ContextmenuItemFolder.Text = "文件夹&J";
this.ContextmenuItemFolder.Click += new System.EventHandler(this.ContextmenuItemFolder_Click);
//
// ContextmenuItemFile
//
this.ContextmenuItemFile.Index = 1;
this.ContextmenuItemFile.Text = "文件&W";
this.ContextmenuItemFile.Click += new System.EventHandler(this.ContextmenuItemFile_Click);
//
// ContextmenuItemDelete
//
this.ContextmenuItemDelete.Index = 1;
this.ContextmenuItemDelete.Text = "删除&D";
this.ContextmenuItemDelete.Click += new System.EventHandler(this.ContextmenuItemDelete_Click);
//
// imageLarge
//
this.imageLarge.ImageSize = new System.Drawing.Size(16, 16);
this.imageLarge.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageLarge.ImageStream")));
this.imageLarge.TransparentColor = System.Drawing.Color.Transparent;
//
// imageSmall
//
this.imageSmall.ImageSize = new System.Drawing.Size(16, 16);
this.imageSmall.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageSmall.ImageStream")));
this.imageSmall.TransparentColor = System.Drawing.Color.Transparent;
//
// ContextmenuItemFresh
//
this.ContextmenuItemFresh.Index = 2;
this.ContextmenuItemFresh.Text = "刷新(&F)";
this.ContextmenuItemFresh.Click += new System.EventHandler(this.ContextmenuItemFresh_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(392, 265);
this.Controls.Add(this.FilesView);
this.Controls.Add(this.btnUp);
this.Controls.Add(this.txtCurPath);
this.Controls.Add(this.label1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -