也打造资源管理器——功能完善版
实现文件的删除、重命名、复制、剪切、粘贴与运行,文件夹的新建、删除、重命名、复制、移动、向上和刷新功能,并能统计选中的文件、文件夹与驱动器的各种信息。界面如下:
实现文件的删除、重命名、复制、剪切、粘贴与运行,文件夹的新建、删除、重命名、复制、移动、向上和刷新功能,并能统计选中的文件、文件夹与驱动器的各种信息。界面如下:
提供驱动器操作的类:
using System;
using System.Collections;
using System.Management;
namespace MyExplorer
{
/**//// <summary>
/// 此类提供所有驱动器信息。
/// </summary>
public class MyDriveHelper
{
public MyDriveHelper()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/**//// <summary>
/// 获取所有驱动器信息
/// </summary>
/// <returns></returns>
public static ArrayList GetAllDrive()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_LogicalDisk");
MyDriveObj myDrvObj;
ArrayList arr = new ArrayList();
foreach(ManagementObject sysDrvObj in searcher.Get())
{
myDrvObj = new MyDriveObj();
FillDrvObj(myDrvObj,sysDrvObj);
arr.Add(myDrvObj);
}
return arr;
}
/**//// <summary>
/// 根据WQL查询返回的对象填充MyDriveObj对象返回
/// </summary>
/// <param name="myDrvObj"></param>
/// <param name="sysDrvObj"></param>
public static void FillDrvObj(MyDriveObj myDrvObj,ManagementObject sysDrvObj)
{
if(sysDrvObj == null || myDrvObj == null)
return;
myDrvObj.Description = sysDrvObj["Description"].ToString();
myDrvObj.DeviceID = sysDrvObj["DeviceID"].ToString();
switch(sysDrvObj["DriveType"].ToString())
{
case "0":
myDrvObj.DriveTypeStr = "未知设备";
break;
case "1":
myDrvObj.DriveTypeStr = "无根目录";
break;
case "2":
myDrvObj.DriveTypeStr = "可移动磁盘";
break;
case "3":
myDrvObj.DriveTypeStr = "本地硬盘";
break;
case "4":
myDrvObj.DriveTypeStr = "网络硬盘";
break;
case "5":
myDrvObj.DriveTypeStr = "CD驱动器";
break;
case "6":
myDrvObj.DriveTypeStr = "内存虚拟磁盘";
break;
}
//System.Windows.Forms.MessageBox.Show(sysDrvObj.ToString());
if(sysDrvObj["FileSystem"] != null)
myDrvObj.FileSystem = sysDrvObj["FileSystem"].ToString();
if(sysDrvObj["FreeSpace"] == null)
myDrvObj.FreeSpace = 0;
else
myDrvObj.FreeSpace = long.Parse(sysDrvObj["FreeSpace"].ToString());
if(sysDrvObj["Size"] == null)
myDrvObj.Size = 0;
else
myDrvObj.Size = long.Parse(sysDrvObj["Size"].ToString());
if(sysDrvObj["VolumeName"] != null)
myDrvObj.VolumeName = sysDrvObj["VolumeName"].ToString();
if(sysDrvObj["VolumeSerialNumber"] != null)
myDrvObj.VolumeSerialNumber = sysDrvObj["VolumeSerialNumber"].ToString();
}
/**//// <summary>
/// '根据DeviceID获取DrvObj对象
/// </summary>
/// <param name="deviceID"></param>
/// <returns></returns>
private MyDriveObj GetDrvObjByDeviceID(string deviceID)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_LogicalDisk Where DeviceID='" + deviceID + "'");
MyDriveObj myDrvObj;
foreach(ManagementObject sysDrvObj in searcher.Get())
{
myDrvObj = new MyDriveObj();
FillDrvObj(myDrvObj,sysDrvObj);
return myDrvObj;
}
return null;
}
}
/**//// <summary>
/// 此类提供所用到的驱动器信息
/// </summary>
public class MyDriveObj
{
public string DeviceID;
public string DriveTypeStr;
public string Description;
public System.Int64 Size;
public System.Int64 FreeSpace;
public string VolumeName;
public string VolumeSerialNumber;
public string FileSystem;
}
}
提供文件操作的类:
using System;
using System.Windows.Forms;
using System.IO;
using System.Collections;
namespace MyExplorer
{
/**//// <summary>
/// 提供文件操作的功能。
/// </summary>
public class MyFileHelper
{
public MyFileHelper(ListView FileListView1,TextBox textBox1)
{
this._lst = FileListView1;
this._lst.AfterLabelEdit += new LabelEditEventHandler(_lst_AfterLabelEdit);
this._txtInfo = textBox1;
}
private ListView _lst;
private TextBox _txtInfo;
//文件的路径,以"\"结尾
public string DirPath = "";
public ListView FileListView
{
get
{
return _lst;
}
set
{
_lst = value;
}
}
/**//// <summary>
/// 删除选中的文件
/// </summary>
public void Delete()
{
if(_lst.SelectedItems.Count == 0 || DirPath == "")
return;
FileInfo fileObj;
foreach(ListViewItem item in _lst.SelectedItems)
{
fileObj = new FileInfo(DirPath + item.Text);
try
{
fileObj.Delete();
}
catch(UnauthorizedAccessException ex)
{
MessageBox.Show("无法永久删除文件。系统信息:" + ex.Message);
return;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
_lst.Items.Remove(item);
}
}
/**//// <summary>
/// 修改文件名
/// </summary>
public void Rename()
{
if(this._lst.SelectedItems.Count != 1 || DirPath == "")
return;
ListViewItem item = this._lst.SelectedItems[0];
FileInfo fileObj = new FileInfo(DirPath + item.Text);
if(fileObj.Attributes.ToString().IndexOf("ReadOnly") != -1)
return;
item.BeginEdit();
}
/**//// <summary>
/// 完成文件名修改功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void _lst_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
if(e.Label == null)
return;
FileInfo fileObj = new FileInfo(DirPath + this._lst.Items[e.Item].Text);
string newPath = DirPath + e.Label;
try
{
fileObj.MoveTo(newPath);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
ArrayList copyFiles = new ArrayList();
ArrayList cutFiles = new ArrayList();
/**//// <summary>
/// 复制文件
/// </summary>
public void Copy()
{
if(_lst.SelectedItems.Count == 0 || DirPath == "")
return;
copyFiles.Clear();
cutFiles.Clear();
foreach(ListViewItem item in _lst.SelectedItems)
{
copyFiles.Add(DirPath + item.Text);
}
}
/**//// <summary>
/// 剪切文件
/// </summary>
public void Cut()
{
if(_lst.SelectedItems.Count == 0 || DirPath == "")
return;
copyFiles.Clear();
cutFiles.Clear();
foreach(ListViewItem item in _lst.SelectedItems)
{
cutFiles.Add(DirPath + item.Text);
}
}
/**//// <summary>
/// 粘贴文件
/// </summary>
public void Paste()
{
FileInfo fileObj;
ListViewItem item;
foreach(string cfile in copyFiles)
{
fileObj = new FileInfo(cfile);
fileObj.CopyTo(DirPath + fileObj.Name);
item = this.FileListView.Items.Add(fileObj.Name);
item.ImageIndex = 3;
}
string file;
if(cutFiles.Count == 0)
return;
for(int i=0; i<cutFiles.Count;i++)
{
file = cutFiles[i].ToString();
fileObj = new FileInfo(file);
if(fileObj.Attributes.ToString().IndexOf("ReadOnly") != -1)
{
MessageBox.Show("文件只读!放弃操作。");
break;
}
try
{
File.Copy(fileObj.FullName,this.DirPath + fileObj.Name,true);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
item = this.FileListView.Items.Add(fileObj.Name);
item.ImageIndex = 3;
try
{
fileObj.Delete();
}
catch(UnauthorizedAccessException ex)
{
MessageBox.Show("无法删除源文件:" + fileObj.Name + " 系统提示:" + ex.Message);
cutFiles.Clear();
return;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
cutFiles.Clear();
return;
}
}
cutFiles.Clear();
}
/**//// <summary>
/// 运行或打开文件
/// </summary>
public void Run()
{
if(this._lst.SelectedItems.Count != 1 || DirPath == "")
return;
ListViewItem item = this._lst.SelectedItems[0];
string fileName = DirPath + item.Text;
try
{
System.Diagnostics.Process.Start(fileName);
}
catch(System.ComponentModel.Win32Exception ex)
{
MessageBox.Show(ex.Message);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/**//// <summary>
/// 显示文件信息
/// </summary>
public void ShowInfo()
{
if(_lst.SelectedItems.Count == 0 || DirPath == "")
return;
ListViewItem item;
string fileName;
FileInfo fileObj = new FileInfo("abc");//创建临时文件对象
long totalSize = 0;
int fileCount = this._lst.SelectedItems.Count;
for(int i=0; i<fileCount; i++)
{
item = this._lst.SelectedItems[i];
fileName = DirPath + item.Text;
fileObj = new FileInfo(fileName);
totalSize += fileObj.Length;
}
string strInfo;
if(fileCount == 1)
{
strInfo = "文件名:{0} 大小:{1}字节 /{2} KB/{3} MB ";
strInfo = string.Format(strInfo,fileObj.FullName,totalSize,(int)(totalSize/1024),(int)(totalSize/(1024*1024)));
strInfo += "\r\n";
strInfo += string.Format("创建时间:{0} 上次访问时间:{1}",fileObj.CreationTime,fileObj.LastAccessTime);
strInfo += "\r\n";
strInfo += "文件属性:";
//MessageBox.Show(fileObj.Attributes.ToString());
if(fileObj.Attributes.ToString().IndexOf("Archive") != -1)
strInfo += "文档 ";
if(fileObj.Attributes.ToString().IndexOf("Compressed") != -1)
strInfo += "压缩 ";
if(fileObj.Attributes.ToString().IndexOf("Encrypted") != -1)
strInfo += "加密 ";
if(fileObj.Attributes.ToString().IndexOf("Hidden") != -1)
strInfo += "隐藏 ";
if(fileObj.Attributes.ToString().IndexOf("Normal") != -1)
strInfo += "普通 ";
if(fileObj.Attributes.ToString().IndexOf("ReadOnly") != -1)
strInfo += "只读 ";
if(fileObj.Attributes.ToString().IndexOf("System") != -1)
strInfo += "系统 ";
if(fileObj.Attributes.ToString().IndexOf("Temporary") != -1)
strInfo += "临时文档 ";
}
else
{
strInfo = string.Format("选中了{0}个文件",fileCount);
strInfo += "\r\n";
strInfo += string.Format("大小:{0}字节/{1} KB/{2} MB",totalSize,(int)(totalSize/1024),(int)(totalSize/(1024*1024)));
}
this._txtInfo.Text = strInfo;
}
}
}
using System;
using System.Windows.Forms;
using System.Collections;
using System.IO;
namespace MyExplorer
{
/**//// <summary>
///提供文件夹树的操作功能。
/// </summary>
public class MyDirectoryTreeHelper
{
public MyDirectoryTreeHelper(TreeView tree,ListView lst,TextBox txtInfo)
{
this._tree = tree;
this.FileLstCtl = lst;
this.txtInfo = txtInfo;
this._tree.AfterLabelEdit += new NodeLabelEditEventHandler(_tree_AfterLabelEdit);
this._tree.AfterSelect += new TreeViewEventHandler(_tree_AfterSelect);
}
/**//// <summary>
/// 装入所有驱动器盘符
/// </summary>
public void LoadAllDriveToTree()
{
ArrayList arr = MyDriveHelper.GetAllDrive();
_tree.Nodes.Clear();
TreeNode root = _tree.Nodes.Add("我的电脑");
_tree.SelectedNode = root;
root.ImageIndex = 4;
root.SelectedImageIndex = 4;
TreeNode tmpnode;
foreach(MyDriveObj obj in arr)
{
tmpnode = this.AddSelectedNodeChild(obj.DeviceID);
tmpnode.Tag = obj;//将驱动器信息对象存放到树节点中
tmpnode.ImageIndex = 0;
tmpnode.SelectedImageIndex = 0;
}
root.Expand();
}
变量区#region 变量区
TreeView _tree = null;
ListView FileLstCtl;
FolderBrowserDialog ChooseFolder = new FolderBrowserDialog();
TextBox txtInfo;
bool IsNewDir = false;
/**//// <summary>
/// 显示文件夹的树
/// </summary>
public TreeView TreeCtl
{
get
{
return _tree;
}
set
{
_tree = value;
}
}
#endregion
树节点操作#region 树节点操作
/**//// <summary>
/// 给选中的节点增加子节点
/// </summary>
/// <param name="NodeText"></param>
/// <returns></returns>
private TreeNode AddSelectedNodeChild(string NodeText)
{
if(_tree.SelectedNode == null)
{
return null;
}
TreeNode node = new TreeNode(NodeText);
_tree.SelectedNode.Nodes.Add(node);
return node;
}
/**//// <summary>
/// 删除选中的节点
/// </summary>
private void DeleteSelectedNode()
{
try
{
_tree.Nodes.Remove(_tree.SelectedNode);
_tree.SelectedNode = null;
}
catch
{}
}
/**//// <summary>
/// 更改选中节点的文本
/// </summary>
private void RenameSelectedNode()
{
if(_tree.SelectedNode == null)
{
return;
}
_tree.SelectedNode.BeginEdit();
}
#endregion
点击树节点相关操作#region 点击树节点相关操作
/**//// <summary>
/// 获取特定节点的层数
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private int GetNodeLevel(TreeNode node)
{
if(node == null)
{
return -1;
}
if(node.Parent == null)
{
return 0;
}
int level = 0;
TreeNode tmpnode = node.Parent;
while(!(tmpnode == null))
{
level++;
tmpnode = tmpnode.Parent;
}
return level;
}
/**//// <summary>
/// 根据指定节点生成表示此节点的路径
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
public string GetNodePathStr(TreeNode node)
{
if(node == null)
{
return "";
}
if(node.Parent == null)
{
return "";
}
Stack pathStack = new Stack();
string strPath = "";
pathStack.Push(node.Text);
while(node.Parent != null)
{
pathStack.Push(node.Parent.Text);
node = node.Parent;
}
int count = pathStack.Count;
for(int i=0; i<count; i++)
{
if( i > 0)
{
if(i == 1)
strPath = pathStack.Pop().ToString();
else
strPath += "\\" + pathStack.Pop().ToString();
}
else
{
pathStack.Pop();
}
}
return strPath + "\\";
}
/**//// <summary>
/// 获取对应节点的DirectoryInfo对象
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
public DirectoryInfo GetDirObj(TreeNode node)
{
if(node == null)
return null;
string strPath = this.GetNodePathStr(node);
if(strPath == "")
return null;
DirectoryInfo dirObj = new DirectoryInfo(strPath);
return dirObj;
}
/**//// <summary>
/// 根据DirectoryInfo对象填充文件列表
/// </summary>
/// <param name="dirObj"></param>
/// <returns></returns>
private bool FillFileList(DirectoryInfo dirObj)
{
if(dirObj == null)
return false;
if(this.FileLstCtl == null)
return false;
if(IsNewDir)
{
this.FileLstCtl.Clear();
return false;
}
FileInfo[] files;
try
{
files = dirObj.GetFiles();
}
catch(IOException ex)
{
MessageBox.Show("请将磁盘或光盘插入驱动器"+dirObj.Name+"中。系统提示:"+ex.Message);
return false;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
this.FileLstCtl.Clear();
ListViewItem item;
foreach(FileInfo tmpfile in files)
{
item = this.FileLstCtl.Items.Add(tmpfile.Name);
item.ImageIndex = 3;
}
return true;
}
/**//// <summary>
/// 填充子文件夹节点,清空原有子树
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private bool FillSubDirList(TreeNode node)
{
if(node == null)
return false;
if(IsNewDir)
{
this.FileLstCtl.Clear();
return false;
}
string strPath;
DirectoryInfo[] dirs;
node.Nodes.Clear();
strPath = this.GetNodePathStr(node);
DirectoryInfo dirObj = new DirectoryInfo(strPath);
try
{
dirs = dirObj.GetDirectories();
}
catch(IOException ex)
{
MessageBox.Show("请将磁盘或光盘插入驱动器"+dirObj.Name+"中。系统提示:"+ex.Message);
return false;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
foreach(DirectoryInfo tmpdir in dirs)
{
this.AddSelectedNodeChild(tmpdir.Name);
}
return true;
}
/**//// <summary>
/// 当用户单击节点时…
/// </summary>
private void OnClickNode()
{
if(_tree.SelectedNode == null)
return;
TreeNode node = _tree.SelectedNode;
if(node == _tree.Nodes[0])
{
FileLstCtl.Clear();
return;
}
DirectoryInfo dirobj;
if(this.GetNodeLevel(node) == 1)
{
if(this.FillSubDirList(node) == false)
return;
dirobj = new DirectoryInfo(this.GetNodePathStr(node));
if(this.FillFileList(dirobj) == false)
return;
node.Expand();
return;
}
string strPath = this.GetNodePathStr(node);
dirobj = new DirectoryInfo(strPath);
if(this.FillFileList(dirobj) == false)
return;
if(this.FillSubDirList(node) == false)
return;
node.Expand();
}
#endregion
对外功能接口区#region 对外功能接口区
/**//// <summary>
/// 删除文件夹
/// </summary>
public void Delete()
{
TreeNode node = _tree.SelectedNode;
DirectoryInfo dirObj = GetDirObj(node);
dirObj.Delete(true);//删除文件夹、其子文件夹与文件
this.DeleteSelectedNode();
this.FileLstCtl.Clear();
}
/**//// <summary>
/// 复制文件夹
/// </summary>
public void CopyTo()
{
TreeNode node = _tree.SelectedNode;
DirectoryInfo dirObj = this.GetDirObj(node);
if(this.ChooseFolder.ShowDialog() == DialogResult.OK)
{
string strPath = this.ChooseFolder.SelectedPath;
if(this.CopyDirectory(dirObj.FullName,strPath))
MessageBox.Show("复制完成!");
}
}
private bool flag = false;//首次执行时先建一个sourcePath文件夹
/**//// <summary>
/// 将文件夹sourcePath复制到另一个文件夹targetPath
/// </summary>
/// <param name="sourcePath">源文件夹</param>
/// <param name="targetPath">目标文件夹</param>
/// <returns></returns>
private bool CopyDirectory(string sourcePath,string targetPath)
{
if(sourcePath.Trim() == String.Empty || targetPath.Trim() == String.Empty)
return false;
DirectoryInfo source = new DirectoryInfo(sourcePath);
if(source == null)
return false;
if(!Directory.Exists(targetPath))
return false;
DirectoryInfo target = new DirectoryInfo(targetPath);
if(target == null)
return false;
try
{
if(!flag)//创建根文件夹
{
target = target.CreateSubdirectory(source.Name);
flag = true;
}
DirectoryInfo[] dirs = source.GetDirectories();
foreach(DirectoryInfo dirObj in dirs)
{
//创建子文件夹
target.CreateSubdirectory(dirObj.Name);
//递归
CopyDirectory(dirObj.FullName,target.FullName + "\\" +dirObj.Name);
}
//复制文件
FileInfo[] files = source.GetFiles();
foreach(FileInfo fileObj in files)
{
File.Copy(fileObj.FullName,target.FullName + "\\" +fileObj.Name,true);
}
}
catch(IOException ex)
{
MessageBox.Show("目标文件夹已经存在!系统提示:" + ex.Message);
return false;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
return true;
}
/**//// <summary>
/// 移动文件夹
/// </summary>
public void MoveTo()
{
string strPath;
TreeNode node = _tree.SelectedNode;
DirectoryInfo dirObj = this.GetDirObj(node);
if(this.ChooseFolder.ShowDialog() == DialogResult.OK)
{
strPath = this.ChooseFolder.SelectedPath;
//复制文件夹
if(this.CopyDirectory(dirObj.FullName,strPath) == false)
return;
}
try
{
//删除文件夹
dirObj.Delete(true);
}
catch(System.UnauthorizedAccessException ex)
{
MessageBox.Show("无法删除源文件夹及文件。系统提示:"+ex.Message);
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
//删除选中的节点
this.DeleteSelectedNode();
//清空文件夹
this.FileLstCtl.Clear();
}
/**//// <summary>
/// 新建文件夹
/// </summary>
/// <returns></returns>
public void NewDir()
{
if(this._tree.SelectedNode == null)
return;
TreeNode node = this._tree.SelectedNode;
DirectoryInfo dirObj = this.GetDirObj(node);
if(dirObj.Attributes.ToString().IndexOf("ReadOnly") != -1 || dirObj.Attributes.ToString().IndexOf("System") != -1)
return;
TreeNode tmpnode = this.AddSelectedNodeChild("新建文件夹");
this._tree.SelectedNode = tmpnode;
IsNewDir = true;
this.RenameSelectedNode();
}
/**//// <summary>
/// 获取文件夹所占磁盘空间大小
/// </summary>
/// <param name="dirObj"></param>
/// <returns></returns>
private long GetDirectorySize(DirectoryInfo dirObj)
{
FileInfo[] files = dirObj.GetFiles();
DirectoryInfo[] dirs = dirObj.GetDirectories();
long totalSize = 0;
foreach(FileInfo file in files)
{
totalSize += file.Length/1024;
}
foreach(DirectoryInfo dir in dirs)
{
totalSize += GetDirectorySize(dir);//递归
}
return totalSize;
}
private bool inReNameMode = false;
private void _tree_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
TreeNode node = this._tree.SelectedNode;
if(IsNewDir)
{
DirectoryInfo dirObj = this.GetDirObj(node);
try
{
if(e.Label == null)
dirObj.CreateSubdirectory(e.Node.Text);
else
dirObj.CreateSubdirectory(e.Label);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
IsNewDir = false;
}
}
if(inReNameMode)
{
if(e.Label == null)
return;
string newPath = this.GetNodePathStr(node.Parent) + e.Label;
DirectoryInfo dirObj = this.GetDirObj(node);
try
{
dirObj.MoveTo(newPath);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
inReNameMode = false;
}
}
}
/**//// <summary>
/// 重命名文件夹
/// </summary>
public void Rename()
{
TreeNode node = this._tree.SelectedNode;
DirectoryInfo dirObj = this.GetDirObj(node);
if(dirObj.Attributes.ToString().IndexOf("ReadOnly") != -1)
return;
inReNameMode = true;
this.RenameSelectedNode();
}
/**//// <summary>
/// 上一级
/// </summary>
public void UpLevel()
{
TreeNode node = this._tree.SelectedNode;
if(node == null || node.Parent == null)
return;
this._tree.SelectedNode = node.Parent;
}
/**//// <summary>
/// 刷新
/// </summary>
public void Refresh()
{
this._tree.Nodes.Clear();
this.FileLstCtl.Clear();
this.LoadAllDriveToTree();
}
/**//// <summary>
/// 显示信息
/// </summary>
/// <param name="CalcFolderSize"></param>
public void ShowInfo(bool CalcFolderSize)
{
TreeNode node = this._tree.SelectedNode;
if(node == null || node.Parent == null)
return;
if(this.GetNodeLevel(node) == 1)
this.ShowDriveInfo(node.Tag as MyDriveObj);
else
this.ShowDirectoryInfo(this.GetDirObj(node),CalcFolderSize);
}
/**//// <summary>
/// 显示驱动器信息
/// </summary>
/// <param name="drvObj"></param>
private void ShowDriveInfo(MyDriveObj drvObj)
{
if(drvObj == null)
return;
string strInfo = drvObj.DeviceID + " " + drvObj.Description + " " + drvObj.DriveTypeStr;
strInfo += "\r\n";
strInfo += string.Format("总容量:{0} KB/{1} MB/{2} GB",(long)(drvObj.Size/1024),(long)(drvObj.Size/(1024*1024)),(long)(drvObj.Size/(1024*1024*1024)));
strInfo += "\r\n";
strInfo += string.Format("剩余空间容量:{0} KB/{1} MB/{2} GB",(long)(drvObj.FreeSpace/1024),(long)(drvObj.FreeSpace/(1024*1024)),(long)(drvObj.FreeSpace/(1024*1024*1024)));
strInfo += "\r\n";
strInfo += string.Format("文件系统:{0} 卷名:{1} 卷序列号:{2}",drvObj.FileSystem,drvObj.VolumeName,drvObj.VolumeSerialNumber);
this.txtInfo.Text = strInfo;
}
/**//// <summary>
/// 显示文件夹信息
/// </summary>
/// <param name="dirObj"></param>
/// <param name="CalcFolderSize"></param>
private void ShowDirectoryInfo(DirectoryInfo dirObj,bool CalcFolderSize)
{
if(dirObj == null || IsNewDir)
return;
string strInfo = "文件夹 {0} 共有文件{1}个,子文件夹{2}个";
FileInfo[] files = null;
DirectoryInfo[] dirs = null ;
try
{
files = dirObj.GetFiles();
}
catch(DirectoryNotFoundException ex)
{
return;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
try
{
dirs = dirObj.GetDirectories();
}
catch(UnauthorizedAccessException ex)
{
return;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
strInfo = string.Format(strInfo,dirObj.Name,files.Length,dirs.Length);
strInfo += "\r\n";
if(CalcFolderSize)
{
long size = this.GetDirectorySize(dirObj);
strInfo += string.Format("总容量:{0} KB/{1} MB",size,(int)(size/1024));
strInfo += "\r\n";
}
strInfo += string.Format("创建时间:{0} 上次访问时间:{1}",dirObj.CreationTime,dirObj.LastAccessTime);
strInfo += "\r\n";
this.txtInfo.Text = strInfo;
}
private void _tree_AfterSelect(object sender, TreeViewEventArgs e)
{
OnClickNode();
}
#endregion
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace MyExplorer
{
/**//// <summary>
/// MyExplorer 的摘要说明。
/// </summary>
public class MyExplorer : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel WestPanel;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Panel BottomPanel;
private System.Windows.Forms.Panel SouthPanel;
private System.Windows.Forms.Splitter splitter2;
private System.Windows.Forms.Panel NorthPanel;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.TextBox txtInfo;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.CheckBox ckbCalcFolderSize;
private System.Windows.Forms.LinkLabel lnkNewDir;
private System.Windows.Forms.LinkLabel lnkDelete;
private System.Windows.Forms.LinkLabel lnkRename;
private System.Windows.Forms.LinkLabel lnkMoveUp;
private System.Windows.Forms.LinkLabel lnkCopyTo;
private System.Windows.Forms.LinkLabel lnkMoveTo;
private System.Windows.Forms.LinkLabel lnkRefresh;
private System.Windows.Forms.LinkLabel lnkDeleteFile;
private System.Windows.Forms.LinkLabel lnkRenameFile;
private System.Windows.Forms.LinkLabel lnkCopyFile;
private System.Windows.Forms.LinkLabel lnkPasteFile;
private System.Windows.Forms.LinkLabel lnkCutFile;
private System.Windows.Forms.LinkLabel lnkOpenOrRunFile;
private System.Windows.Forms.Label label2;
private System.ComponentModel.IContainer components;
private MyDirectoryTreeHelper dirTreeObj;
private System.Windows.Forms.ImageList ImageList1;
private MyFileHelper fileObj;
public MyExplorer()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
dirTreeObj = new MyDirectoryTreeHelper(treeView1,listView1,txtInfo);
dirTreeObj.LoadAllDriveToTree();
fileObj = new MyFileHelper(listView1,txtInfo);
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MyExplorer));
this.WestPanel = new System.Windows.Forms.Panel();
this.lnkNewDir = new System.Windows.Forms.LinkLabel();
this.ckbCalcFolderSize = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.treeView1 = new System.Windows.Forms.TreeView();
this.lnkDelete = new System.Windows.Forms.LinkLabel();
this.lnkRename = new System.Windows.Forms.LinkLabel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.BottomPanel = new System.Windows.Forms.Panel();
this.NorthPanel = new System.Windows.Forms.Panel();
this.listView1 = new System.Windows.Forms.ListView();
this.splitter2 = new System.Windows.Forms.Splitter();
this.SouthPanel = new System.Windows.Forms.Panel();
this.txtInfo = new System.Windows.Forms.TextBox();
this.lnkMoveUp = new System.Windows.Forms.LinkLabel();
this.lnkCopyTo = new System.Windows.Forms.LinkLabel();
this.lnkMoveTo = new System.Windows.Forms.LinkLabel();
this.lnkRefresh = new System.Windows.Forms.LinkLabel();
this.lnkDeleteFile = new System.Windows.Forms.LinkLabel();
this.lnkRenameFile = new System.Windows.Forms.LinkLabel();
this.lnkCopyFile = new System.Windows.Forms.LinkLabel();
this.lnkPasteFile = new System.Windows.Forms.LinkLabel();
this.lnkCutFile = new System.Windows.Forms.LinkLabel();
this.lnkOpenOrRunFile = new System.Windows.Forms.LinkLabel();
this.label2 = new System.Windows.Forms.Label();
this.ImageList1 = new System.Windows.Forms.ImageList(this.components);
this.WestPanel.SuspendLayout();
this.BottomPanel.SuspendLayout();
this.NorthPanel.SuspendLayout();
this.SouthPanel.SuspendLayout();
this.SuspendLayout();
//
// WestPanel
//
this.WestPanel.Controls.Add(this.lnkNewDir);
this.WestPanel.Controls.Add(this.ckbCalcFolderSize);
this.WestPanel.Controls.Add(this.label1);
this.WestPanel.Controls.Add(this.treeView1);
this.WestPanel.Controls.Add(this.lnkDelete);
this.WestPanel.Controls.Add(this.lnkRename);
this.WestPanel.Controls.Add(this.lnkMoveUp);
this.WestPanel.Controls.Add(this.lnkCopyTo);
this.WestPanel.Controls.Add(this.lnkMoveTo);
this.WestPanel.Controls.Add(this.lnkRefresh);
this.WestPanel.Dock = System.Windows.Forms.DockStyle.Left;
this.WestPanel.Location = new System.Drawing.Point(0, 0);
this.WestPanel.Name = "WestPanel";
this.WestPanel.Size = new System.Drawing.Size(288, 397);
this.WestPanel.TabIndex = 0;
//
// lnkNewDir
//
this.lnkNewDir.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lnkNewDir.Location = new System.Drawing.Point(8, 368);
this.lnkNewDir.Name = "lnkNewDir";
this.lnkNewDir.Size = new System.Drawing.Size(32, 16);
this.lnkNewDir.TabIndex = 3;
this.lnkNewDir.TabStop = true;
this.lnkNewDir.Text = "新建";
this.lnkNewDir.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkNewDir_LinkClicked);
//
// ckbCalcFolderSize
//
this.ckbCalcFolderSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ckbCalcFolderSize.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.ckbCalcFolderSize.Location = new System.Drawing.Point(168, 8);
this.ckbCalcFolderSize.Name = "ckbCalcFolderSize";
this.ckbCalcFolderSize.Size = new System.Drawing.Size(112, 24);
this.ckbCalcFolderSize.TabIndex = 2;
this.ckbCalcFolderSize.Text = "计算文件夹容量";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(8, 6);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(54, 17);
this.label1.TabIndex = 1;
this.label1.Text = "文件夹:";
//
// treeView1
//
this.treeView1.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.treeView1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.treeView1.HideSelection = false;
this.treeView1.ImageIndex = 1;
this.treeView1.ImageList = this.ImageList1;
this.treeView1.LabelEdit = true;
this.treeView1.Location = new System.Drawing.Point(8, 32);
this.treeView1.Name = "treeView1";
this.treeView1.SelectedImageIndex = 2;
this.treeView1.Size = new System.Drawing.Size(272, 328);
this.treeView1.TabIndex = 0;
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
//
// lnkDelete
//
this.lnkDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lnkDelete.Location = new System.Drawing.Point(42, 368);
this.lnkDelete.Name = "lnkDelete";
this.lnkDelete.Size = new System.Drawing.Size(32, 16);
this.lnkDelete.TabIndex = 3;
this.lnkDelete.TabStop = true;
this.lnkDelete.Text = "删除";
this.lnkDelete.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkDelete_LinkClicked);
//
// lnkRename
//
this.lnkRename.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lnkRename.Location = new System.Drawing.Point(76, 368);
this.lnkRename.Name = "lnkRename";
this.lnkRename.Size = new System.Drawing.Size(32, 16);
this.lnkRename.TabIndex = 3;
this.lnkRename.TabStop = true;
this.lnkRename.Text = "改名";
this.lnkRename.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkRename_LinkClicked);
//
// splitter1
//
this.splitter1.BackColor = System.Drawing.Color.Black;
this.splitter1.Location = new System.Drawing.Point(288, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(6, 397);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
//
// BottomPanel
//
this.BottomPanel.Controls.Add(this.NorthPanel);
this.BottomPanel.Controls.Add(this.splitter2);
this.BottomPanel.Controls.Add(this.SouthPanel);
this.BottomPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.BottomPanel.Location = new System.Drawing.Point(294, 0);
this.BottomPanel.Name = "BottomPanel";
this.BottomPanel.Size = new System.Drawing.Size(314, 397);
this.BottomPanel.TabIndex = 2;
//
// NorthPanel
//
this.NorthPanel.Controls.Add(this.listView1);
this.NorthPanel.Controls.Add(this.lnkDeleteFile);
this.NorthPanel.Controls.Add(this.lnkRenameFile);
this.NorthPanel.Controls.Add(this.lnkCopyFile);
this.NorthPanel.Controls.Add(this.lnkPasteFile);
this.NorthPanel.Controls.Add(this.lnkCutFile);
this.NorthPanel.Controls.Add(this.lnkOpenOrRunFile);
this.NorthPanel.Controls.Add(this.label2);
this.NorthPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.NorthPanel.Location = new System.Drawing.Point(0, 0);
this.NorthPanel.Name = "NorthPanel";
this.NorthPanel.Size = new System.Drawing.Size(314, 319);
this.NorthPanel.TabIndex = 2;
//
// listView1
//
this.listView1.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.listView1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.listView1.HideSelection = false;
this.listView1.LabelEdit = true;
this.listView1.LargeImageList = this.ImageList1;
this.listView1.Location = new System.Drawing.Point(16, 32);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(245, 261);
this.listView1.SmallImageList = this.ImageList1;
this.listView1.TabIndex = 0;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
//
// splitter2
//
this.splitter2.BackColor = System.Drawing.Color.Black;
this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.splitter2.Location = new System.Drawing.Point(0, 319);
this.splitter2.Name = "splitter2";
this.splitter2.Size = new System.Drawing.Size(314, 6);
this.splitter2.TabIndex = 1;
this.splitter2.TabStop = false;
//
// SouthPanel
//
this.SouthPanel.Controls.Add(this.txtInfo);
this.SouthPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
this.SouthPanel.Location = new System.Drawing.Point(0, 325);
this.SouthPanel.Name = "SouthPanel";
this.SouthPanel.Size = new System.Drawing.Size(314, 72);
this.SouthPanel.TabIndex = 0;
//
// txtInfo
//
this.txtInfo.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.txtInfo.BackColor = System.Drawing.SystemColors.Info;
this.txtInfo.Location = new System.Drawing.Point(8, 8);
this.txtInfo.Multiline = true;
this.txtInfo.Name = "txtInfo";
this.txtInfo.ReadOnly = true;
this.txtInfo.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtInfo.Size = new System.Drawing.Size(293, 56);
this.txtInfo.TabIndex = 0;
this.txtInfo.Text = "";
//
// lnkMoveUp
//
this.lnkMoveUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lnkMoveUp.Location = new System.Drawing.Point(110, 368);
this.lnkMoveUp.Name = "lnkMoveUp";
this.lnkMoveUp.Size = new System.Drawing.Size(32, 16);
this.lnkMoveUp.TabIndex = 3;
this.lnkMoveUp.TabStop = true;
this.lnkMoveUp.Text = "向上";
this.lnkMoveUp.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkMoveUp_LinkClicked);
//
// lnkCopyTo
//
this.lnkCopyTo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lnkCopyTo.Location = new System.Drawing.Point(144, 368);
this.lnkCopyTo.Name = "lnkCopyTo";
this.lnkCopyTo.Size = new System.Drawing.Size(48, 16);
this.lnkCopyTo.TabIndex = 3;
this.lnkCopyTo.TabStop = true;
this.lnkCopyTo.Text = "复制到";
this.lnkCopyTo.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkCopyTo_LinkClicked);
//
// lnkMoveTo
//
this.lnkMoveTo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lnkMoveTo.Location = new System.Drawing.Point(194, 368);
this.lnkMoveTo.Name = "lnkMoveTo";
this.lnkMoveTo.Size = new System.Drawing.Size(48, 16);
this.lnkMoveTo.TabIndex = 3;
this.lnkMoveTo.TabStop = true;
this.lnkMoveTo.Text = "移动到";
this.lnkMoveTo.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkMoveTo_LinkClicked);
//
// lnkRefresh
//
this.lnkRefresh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lnkRefresh.Location = new System.Drawing.Point(244, 368);
this.lnkRefresh.Name = "lnkRefresh";
this.lnkRefresh.Size = new System.Drawing.Size(32, 16);
this.lnkRefresh.TabIndex = 3;
this.lnkRefresh.TabStop = true;
this.lnkRefresh.Text = "刷新";
this.lnkRefresh.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkRefresh_LinkClicked);
//
// lnkDeleteFile
//
this.lnkDeleteFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lnkDeleteFile.AutoSize = true;
this.lnkDeleteFile.Location = new System.Drawing.Point(269, 56);
this.lnkDeleteFile.Name = "lnkDeleteFile";
this.lnkDeleteFile.Size = new System.Drawing.Size(29, 17);
this.lnkDeleteFile.TabIndex = 3;
this.lnkDeleteFile.TabStop = true;
this.lnkDeleteFile.Text = "删除";
this.lnkDeleteFile.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkDeleteFile_LinkClicked);
//
// lnkRenameFile
//
this.lnkRenameFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lnkRenameFile.AutoSize = true;
this.lnkRenameFile.Location = new System.Drawing.Point(269, 89);
this.lnkRenameFile.Name = "lnkRenameFile";
this.lnkRenameFile.Size = new System.Drawing.Size(29, 17);
this.lnkRenameFile.TabIndex = 3;
this.lnkRenameFile.TabStop = true;
this.lnkRenameFile.Text = "改名";
this.lnkRenameFile.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkRenameFile_LinkClicked);
//
// lnkCopyFile
//
this.lnkCopyFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lnkCopyFile.AutoSize = true;
this.lnkCopyFile.Location = new System.Drawing.Point(269, 122);
this.lnkCopyFile.Name = "lnkCopyFile";
this.lnkCopyFile.Size = new System.Drawing.Size(29, 17);
this.lnkCopyFile.TabIndex = 3;
this.lnkCopyFile.TabStop = true;
this.lnkCopyFile.Text = "复制";
this.lnkCopyFile.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkCopyFile_LinkClicked);
//
// lnkPasteFile
//
this.lnkPasteFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lnkPasteFile.AutoSize = true;
this.lnkPasteFile.Location = new System.Drawing.Point(269, 188);
this.lnkPasteFile.Name = "lnkPasteFile";
this.lnkPasteFile.Size = new System.Drawing.Size(29, 17);
this.lnkPasteFile.TabIndex = 3;
this.lnkPasteFile.TabStop = true;
this.lnkPasteFile.Text = "粘贴";
this.lnkPasteFile.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkPasteFile_LinkClicked);
//
// lnkCutFile
//
this.lnkCutFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lnkCutFile.AutoSize = true;
this.lnkCutFile.Location = new System.Drawing.Point(269, 155);
this.lnkCutFile.Name = "lnkCutFile";
this.lnkCutFile.Size = new System.Drawing.Size(29, 17);
this.lnkCutFile.TabIndex = 3;
this.lnkCutFile.TabStop = true;
this.lnkCutFile.Text = "剪切";
this.lnkCutFile.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkCutFile_LinkClicked);
//
// lnkOpenOrRunFile
//
this.lnkOpenOrRunFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lnkOpenOrRunFile.AutoSize = true;
this.lnkOpenOrRunFile.Location = new System.Drawing.Point(269, 232);
this.lnkOpenOrRunFile.Name = "lnkOpenOrRunFile";
this.lnkOpenOrRunFile.Size = new System.Drawing.Size(29, 17);
this.lnkOpenOrRunFile.TabIndex = 3;
this.lnkOpenOrRunFile.TabStop = true;
this.lnkOpenOrRunFile.Text = "打开";
this.lnkOpenOrRunFile.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkOpenOrRunFile_LinkClicked);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(16, 8);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(42, 17);
this.label2.TabIndex = 1;
this.label2.Text = "文件:";
//
// ImageList1
//
this.ImageList1.ImageSize = new System.Drawing.Size(16, 16);
this.ImageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ImageList1.ImageStream")));
this.ImageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// MyExplorer
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(608, 397);
this.Controls.Add(this.BottomPanel);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.WestPanel);
this.Name = "MyExplorer";
this.Text = "资源管理器";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.WestPanel.ResumeLayout(false);
this.BottomPanel.ResumeLayout(false);
this.NorthPanel.ResumeLayout(false);
this.SouthPanel.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MyExplorer());
}
private void lnkNewDir_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.dirTreeObj.NewDir();
}
private void lnkDelete_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.dirTreeObj.Delete();
}
private void lnkRename_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.dirTreeObj.Rename();
}
private void lnkMoveUp_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.dirTreeObj.UpLevel();
}
private void lnkCopyTo_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
this.dirTreeObj.CopyTo();
}
private void lnkMoveTo_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
this.dirTreeObj.MoveTo();
}
private void lnkRefresh_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.dirTreeObj.Refresh();
}
private void lnkDeleteFile_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
OnDeleteFile();
}
private void OnDeleteFile()
{
this.SetFilePath();
this.fileObj.Delete();
}
private void SetFilePath()
{
if(this.treeView1.SelectedNode == this.treeView1.Nodes[0])
return;
string strPath = this.dirTreeObj.GetNodePathStr(this.treeView1.SelectedNode);
this.fileObj.DirPath = strPath;
}
private void lnkRenameFile_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.SetFilePath();
this.fileObj.Rename();
}
private void lnkCopyFile_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.SetFilePath();
this.fileObj.Copy();
}
private void lnkCutFile_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.SetFilePath();
this.fileObj.Cut();
}
private void lnkPasteFile_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.SetFilePath();
this.fileObj.Paste();
}
private void lnkOpenOrRunFile_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.SetFilePath();
this.fileObj.Run();
}
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.SetFilePath();
this.fileObj.ShowInfo();
}
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
this.dirTreeObj.ShowInfo(this.ckbCalcFolderSize.Checked);
}
}
}