📄 browse.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace File_browser
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class browse : System.Windows.Forms.Form
{
private System.Windows.Forms.MenuItem menuExit;
private System.Windows.Forms.MenuItem menuAction;
private System.Windows.Forms.MenuItem menuOpen;
private System.Windows.Forms.MenuItem menuDo;
private System.Windows.Forms.MenuItem menuCopy;
private System.Windows.Forms.MenuItem menuCut;
private System.Windows.Forms.MenuItem menuPaste;
private System.Windows.Forms.ListView FileList;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuShow1;
private System.Windows.Forms.MenuItem menuShow2;
private System.Windows.Forms.MenuItem menuShow3;
private System.Windows.Forms.MenuItem menuShow4;
private System.Windows.Forms.ImageList IconListSmall;
private System.Windows.Forms.ImageList IconListBig;
private System.Windows.Forms.MenuItem menuNew;
private System.Windows.Forms.MenuItem menuNewtxt;
private System.Windows.Forms.MainMenu FileMenu;
private string path = "\\",srcpath,srcfilename;
private bool dorf,porc;
private System.Windows.Forms.MenuItem menuNewf;
private System.Windows.Forms.MenuItem menuRename;
private System.Windows.Forms.MenuItem menuAbout;
private System.Windows.Forms.MenuItem menuDel;
public browse()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.Text = "SmartNotePad v 1.0";
FileList.SmallImageList = this.IconListSmall;
FileList.SmallImageList.ImageSize = new Size(16, 16);
FileList.LargeImageList = this.IconListBig;
FileList.LargeImageList.ImageSize = new Size(32, 32);
GetList();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(browse));
this.FileMenu = new System.Windows.Forms.MainMenu();
this.menuExit = new System.Windows.Forms.MenuItem();
this.menuAction = new System.Windows.Forms.MenuItem();
this.menuNew = new System.Windows.Forms.MenuItem();
this.menuNewtxt = new System.Windows.Forms.MenuItem();
this.menuNewf = new System.Windows.Forms.MenuItem();
this.menuOpen = new System.Windows.Forms.MenuItem();
this.menuDo = new System.Windows.Forms.MenuItem();
this.menuCopy = new System.Windows.Forms.MenuItem();
this.menuCut = new System.Windows.Forms.MenuItem();
this.menuPaste = new System.Windows.Forms.MenuItem();
this.menuDel = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuShow1 = new System.Windows.Forms.MenuItem();
this.menuShow2 = new System.Windows.Forms.MenuItem();
this.menuShow3 = new System.Windows.Forms.MenuItem();
this.menuShow4 = new System.Windows.Forms.MenuItem();
this.menuRename = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuAbout = new System.Windows.Forms.MenuItem();
this.FileList = new System.Windows.Forms.ListView();
this.IconListSmall = new System.Windows.Forms.ImageList();
this.IconListBig = new System.Windows.Forms.ImageList();
//
// FileMenu
//
this.FileMenu.MenuItems.Add(this.menuExit);
this.FileMenu.MenuItems.Add(this.menuAction);
//
// menuExit
//
this.menuExit.Text = "退出";
this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
//
// menuAction
//
this.menuAction.MenuItems.Add(this.menuNew);
this.menuAction.MenuItems.Add(this.menuOpen);
this.menuAction.MenuItems.Add(this.menuDo);
this.menuAction.MenuItems.Add(this.menuItem1);
this.menuAction.MenuItems.Add(this.menuRename);
this.menuAction.MenuItems.Add(this.menuItem8);
this.menuAction.MenuItems.Add(this.menuAbout);
this.menuAction.Text = "文件";
//
// menuNew
//
this.menuNew.MenuItems.Add(this.menuNewtxt);
this.menuNew.MenuItems.Add(this.menuNewf);
this.menuNew.Text = "新建";
//
// menuNewtxt
//
this.menuNewtxt.Text = "文本文件";
this.menuNewtxt.Click += new System.EventHandler(this.menuNewtxt_Click);
//
// menuNewf
//
this.menuNewf.Text = "文件夹";
this.menuNewf.Click += new System.EventHandler(this.menuItem5_Click);
//
// menuOpen
//
this.menuOpen.Text = "打开";
this.menuOpen.Click += new System.EventHandler(this.menuOpen_Click);
//
// menuDo
//
this.menuDo.MenuItems.Add(this.menuCopy);
this.menuDo.MenuItems.Add(this.menuCut);
this.menuDo.MenuItems.Add(this.menuPaste);
this.menuDo.MenuItems.Add(this.menuDel);
this.menuDo.Text = "编辑";
//
// menuCopy
//
this.menuCopy.Text = "复制";
this.menuCopy.Click += new System.EventHandler(this.menuCopy_Click);
//
// menuCut
//
this.menuCut.Text = "剪切";
this.menuCut.Click += new System.EventHandler(this.menuCut_Click);
//
// menuPaste
//
this.menuPaste.Enabled = false;
this.menuPaste.Text = "粘贴";
this.menuPaste.Click += new System.EventHandler(this.menuPaste_Click);
//
// menuDel
//
this.menuDel.Text = "删除";
this.menuDel.Click += new System.EventHandler(this.menuDel_Click);
//
// menuItem1
//
this.menuItem1.MenuItems.Add(this.menuShow1);
this.menuItem1.MenuItems.Add(this.menuShow2);
this.menuItem1.MenuItems.Add(this.menuShow3);
this.menuItem1.MenuItems.Add(this.menuShow4);
this.menuItem1.Text = "显示";
//
// menuShow1
//
this.menuShow1.Text = "大图标";
this.menuShow1.Click += new System.EventHandler(this.menuShow1_Click);
//
// menuShow2
//
this.menuShow2.Text = "小图标";
this.menuShow2.Click += new System.EventHandler(this.menuShow2_Click);
//
// menuShow3
//
this.menuShow3.Text = "列表";
this.menuShow3.Click += new System.EventHandler(this.menuShow3_Click);
//
// menuShow4
//
this.menuShow4.Text = "详细资料";
this.menuShow4.Click += new System.EventHandler(this.menuShow4_Click);
//
// menuRename
//
this.menuRename.Text = "重命名";
this.menuRename.Click += new System.EventHandler(this.menuRename_Click);
//
// menuItem8
//
this.menuItem8.Text = "-";
//
// menuAbout
//
this.menuAbout.Text = "关于";
this.menuAbout.Click += new System.EventHandler(this.menuAbout_Click);
//
// FileList
//
this.FileList.FullRowSelect = true;
this.FileList.View = System.Windows.Forms.View.Details;
this.FileList.ItemActivate += new System.EventHandler(this.FileList_ItemActivate);
//
// IconListSmall
//
this.IconListSmall.Images.Add(((System.Drawing.Image)(resources.GetObject("resource"))));
this.IconListSmall.Images.Add(((System.Drawing.Image)(resources.GetObject("resource1"))));
this.IconListSmall.ImageSize = new System.Drawing.Size(16, 16);
//
// IconListBig
//
this.IconListBig.Images.Add(((System.Drawing.Image)(resources.GetObject("resource2"))));
this.IconListBig.Images.Add(((System.Drawing.Image)(resources.GetObject("resource3"))));
this.IconListBig.ImageSize = new System.Drawing.Size(16, 16);
//
// browse
//
this.Controls.Add(this.FileList);
this.Menu = this.FileMenu;
this.Text = "文件浏览器";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new browse());
}
private void menuExit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
//获取目录以及文件列表
private void GetList()
{
FileList.Clear();
FileList.Columns.Add(path, FileList.Size.Width, HorizontalAlignment.Left);
// Add the list view items
DirectoryInfo dir = new DirectoryInfo(path);
if(path!="\\")
{
ListViewItem item = new ListViewItem("..");
item.ImageIndex = 0;
FileList.Items.Add(item);
}
foreach (DirectoryInfo f in dir.GetDirectories())
{
String name = f.Name;
ListViewItem item = new ListViewItem(name);
item.ImageIndex = 0;
FileList.Items.Add(item);
}
foreach (FileInfo f in dir.GetFiles("*.txt"))
{
String name = f.Name;
ListViewItem item = new ListViewItem(name);
item.ImageIndex = 1;
FileList.Items.Add(item);
}
}
//根据文件后缀判断显示图片的类型
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -