在教程中
本例
下面詳細介紹這個小程序能實現的功能
軟件界面
文件管理器主界面
進入驅動器D盤後的界面
新建文件界面
新建文件夾界面
文本文檔界面
System
System
下面
ListView
通過ListView控件
b SmallIcon:所有選項都在其旁邊顯示一個小圖標和一個標簽
c List:只顯示一列
d Details:可以顯示任意數量的列
ImageList
ImageList 控件包含 ListImage 對象的集合
語法
ImageList 控件的作用象圖像的儲藏室
在設計時
ContextMenuStrip
ContextMenuStrip 控件提供了與某個控件關聯的快捷菜單
例子
//上下文菜單項
ContextMenuStrip
ContextMenuStrip
ContextMenuStrip
ContextMenuStrip
ContextMenuStrip
ContextMenuStrip
這樣就OK了
通過上面的介紹
同時
主要有兩個類
Folder
CODE:
using System;
using System
using System
using System
using System
namespace FileManager
{
public class Folder
{
/// <summary>
/// 新建文件夾
/// </summary>
/// <param name=
/// <param name=
public static void NewFolder(string foldername
{
foldername
//如果輸入信息為空
if (foldername ==
{
MessageBox
return;
}
else
{
string FullName = path +
//如果該文件以及存在
if (Directory
{
MessageBox
return;
}
else
{
//新建文件夾
Directory
}
}
}
/// <summary>
/// 新建文件夾(Enter鍵觸發)
/// </summary>
/// <param name=
/// <param name=
public static void Enter(string foldername
{
foldername
if (foldername ==
{
MessageBox
return;
}
else if (Directory
{
MessageBox
return;
}
else
{
Directory
}
}
/// <summary>
/// //獲取文件夾名
截取
/// </summary>
/// <param name=
/// <returns></returns>
internal static int DirectoryName(string DirectoryPath)
{
int j =
char[] c = DirectoryPath
for (int i = c
{
j = i;
if (c[i]
{
break;//遇
}
}
return j +
}
/// <summary>
/// 在指定目錄下新建一個文件夾
/// </summary>
/// <param name=
/// <param name=
public static void CreateDir(string path
{
Directory
}
/// <summary>
/// 復制文件
/// </summary>
/// <param name=
/// <param name=
/// <param name=
public static void CopyFile(string oldDir
{
File
}
/// <summary>
/// 復制文件
/// </summary>
/// <param name=
/// <param name=
public static void CopyFile(string oldDir
{
string name = oldDir
File
}
/// <summary>
/// 刪除指定文件夾
/// </summary>
/// <param name=
/// <param name=
public static void DeleteFolder(string strDir
{
Directory
}
/// <summary>
/// 返回指定路徑的DirectoryInfo
/// </summary>
/// <returns></returns>
public static DirectoryInfo GetDir(string path)
{
return new DirectoryInfo(path);
}
}
}
Txt
CODE:
using System;
using System
using System
using System
using System
using System
namespace FileManager
{
public class Txt
{
public Txt()
{
}
/// <summary>
/// 新建文件
/// </summary>
/// <param name=
/// <param name=
public static void NewFile(string filename
{
filename
if (filename ==
{
MessageBox
}
else
{
if (File
{
MessageBox
}
else
{
string FullName = path +
StreamWriter Sw = File
}
}
}
/// <summary>
/// 新建文件(Enter鍵觸發)
/// </summary>
/// <param name=
/// <param name=
public static void Enter(string filename
{
filename
if (filename ==
{
MessageBox
}
else
{
if (File
{
MessageBox
}
else
{
string FullName = path +
StreamWriter Sw = File
}
}
}
/// <summary>
/// 讀取顯示
/// </summary>
/// <param name=
/// <param name=
public static string Display(string filename)
{//讀取顯示
try
{
string contents;
FileStream fs = new FileStream(filename
StreamReader reader = new StreamReader(fs); //實例化一個streamreader
contents = reader
fs
return contents;
}
catch (Exception ex)
{
MessageBox
return
}
}
/// <summary>
/// 打開
/// </summary>
/// <param name=
/// <param name=
/// <param name=
public static void Open(OpenFileDialog ofd
{//打開文本
try
{
if (ofd
{
string fileName = ofd
FileStream fs = new FileStream(fileName
StreamReader reader = new StreamReader(fs);
fullname = fileName;
contents = reader
fs
}
}
catch (Exception ex)
{
MessageBox
}
}
/// <summary>
/// 保存
/// </summary>
/// <param name=
/// <param name=
public static void Save(string fullname
{//保存
try
{
StreamWriter writer = new StreamWriter(fullname);
writer
writer
}
catch (Exception ex)
{
MessageBox
}
}
/// <summary>
/// 另存為
/// </summary>
/// <param name=
/// <param name=
public static void SaveAs(SaveFileDialog sfd
{
if (sfd
{
string fileName = sfd
try
{
Stream stream = File
using (StreamWriter writer = new StreamWriter(stream))
{
writer
writer
}
}
catch (Exception ex)
{
MessageBox
}
}
}
/// <summary>
/// 粗體
/// </summary>
/// <param name=
public static void Bold(RichTextBox rtb)
{
Font newFont = new Font(rtb
(rtb
rtb
rtb
rtb
}
/// <summary>
/// 斜體
/// </summary>
/// <param name=
public static void Italic(RichTextBox rtb)
{
Font newFont = new Font(rtb
(rtb
rtb
rtb
rtb
}
/// <summary>
/// 下劃線
/// </summary>
/// <param name=
public static void Underline(RichTextBox rtb)
{
Font newFont = new Font(rtb
(rtb
rtb
rtb
rtb
}
/// <summary>
/// 復制
/// </summary>
/// <param name=
public static void Copy(RichTextBox rtb)
{
if (rtb
return;
Clipboard
}
/// <summary>
/// 剪切
/// </summary>
/// <param name=
public static void Cut(RichTextBox rtb)
{
if (rtb
{
try
{
rtb
}
catch (Exception ex)
{
MessageBox
}
}
}
/// <summary>
/// 粘貼
/// </summary>
/// <param name=
public static void Paste(RichTextBox rtb)
{
rtb
}
/// <summary>
/// 退出
/// </summary>
/// <param name=
/// <param name=
public static void Exit(string fullname
{
if (MessageBox
{
try
{
StreamWriter writer = new StreamWriter(fullname);
writer
writer
}
catch (Exception ex)
{
MessageBox
}
}
}
/// <summary>
/// 在指定目錄新建一個文本文件
/// </summary>
/// <param name=
/// <param name=
/// <returns></returns>
public static StreamWriter CreateText(string path
{
return File
}
/// <summary>
/// 刪除指定文件
/// </summary>
/// <param name=
public static void DeleteFile(string strFile)
{
File
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11857.html