C#資源管理器原始碼(帶圖示顯示),思歸、橙子鳥 、斑主請進,大家請進。 (轉)
原始碼(帶圖示顯示),思歸、橙子鳥 、斑主請進,大家請進。
粘上一篇拙作,供大家評頭論足。聽說思歸先生德才兼備。很想得到您的指正。看到橙子鳥先生的言論。很是新鮮,是非自有公論。我雖不讚美,卻也不反感。特請橙子鳥先生進來一罵。但要罵的具體。例“xx句太臭”。我也喜歡菜鳥的吹棒,畢竟順耳。總之,歡迎評頭論足。吹棒使我信心倍加,罵聲使我清醒努力。
請問斑主,怎樣才能增加分,我的分不多,還有好多問題請教大家。是不是發表點什麼就可以得分。如認為我有所貢獻,請多給我些分。先謝了。
順便請教大家一個問題如下:
float f1 = 2.11111f;
dc.DrawString(f1.ToString(),font,brush,8,8);
在第一個引數中我想輸出小數點後2位,而不是5位。該怎麼截掉後3位。
//C#資源管理器原始碼
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System..Forms;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;
namespace myTree
{
///
/// Form1 的摘要說明。
///
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.Statar statusBar1;
private System.Windows.Forms.StatusBanel 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("%System%system3232.dll",15);
TreeImageList.Images.Add(ic0);
Icon ic1=myExtractIcon("%SystemRoot%system32shell32.dll",5);
TreeImageList.Images.Add(ic1);
Icon ic2=myExtractIcon("%SystemRoot%system32shell32.dll",7);
TreeImageList.Images.Add(ic2);
Icon ic3=myExtractIcon("%SystemRoot%system32shell32.dll",11);
TreeImageList.Images.Add(ic3);
Icon ic4=myExtractIcon("%SystemRoot%system32shell32.dll",3);
TreeImageList.Images.Add(ic4);
Icon ic5=myExtractIcon("%SystemRoot%system32shell32.dll",4);
TreeImageList.Images.Add(ic5);
Icon ic6=myExtractIcon("%SystemRoot%system32shell32.dll",101);
TreeImageList.Images.Add(ic6);
GetDrive();
}
///
/// 清理所有正在使用的資源。
///
protected overr void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows FoDesigner generated code
///
/// 設計器支援所需的方法 - 不要使用程式碼編輯器修改
/// 此方法的內容。
///
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.edImageIndex = -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
///
/// 應用的主入口點。
///
[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 pi,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;
}
}
catch(Exception ex)
{ MessageBox.Show(ex.Message,"錯誤提示",0,MessageBoxIcon.Error);}
}
else
{
int iTotal=(int)SHGetFileInfo(FileName,0,ref fi,100, 257);
try
{
if(iTotal >0)
{
Icon ic=Icon.FromHandle(fi.hIcon);
imageList.Images.Add(ic);
//return ic;
}
}
catch(Exception ex)
{ MessageBox.Show(ex.Message,"錯誤提示",0,MessageBoxIcon.Error);}
}
// return null;
}
//*************************************************************************************
public void GetDrive()
{
treeView1.ImageList=TreeImageList;
treeView1.BeginUpdate();
treeView1.Nodes.Clear();
TreeNode RootNode=new TreeNode("我的",0,0);
treeView1.Nodes.Add(RootNode);
int iImageIndex=2; int iSelectedIndex=2;
string[] astrDrives = Directory.GetLogicalDrives();
foreach (string str in astrDrives)
{
if(str == "A:")
{ iImageIndex=1; iSelectedIndex=1;}
else if(str == "G:")
{ iImageIndex=3; iSelectedIndex=3;}
else
{ iImageIndex=2; iSelectedIndex=2;}
TreeNode tnDrive = new TreeNode(str, iImageIndex,iSelectedIndex);
treeView1.Nodes[0].Nodes.Add(tnDrive);
AddDirectories(tnDrive);
if(str == "C:")
{ treeView1.SelectedNode=tnDrive;}
}
treeView1.EndUpdate();
}
//*************************************************************************************
void AddDirectories(TreeNode tn)
{
tn.Nodes.Clear();
string strPath=tn.FullPath;
strPath=strPath.Remove(0,5);
//獲得當前目錄
DirectoryInfo dirinfo = new DirectoryInfo(strPath);
DirectoryInfo[] adirinfo;
try
{
adirinfo = dirinfo.GetDirectories();
}
catch
{ return;}
int iImageIndex=4; int iSelectedIndex=5;
foreach (DirectoryInfo di in adirinfo)
{
if(di.Name=="RECYCLER"||di.Name=="RECYCLED"||di.Name=="Recycled")
{iImageIndex=6; iSelectedIndex=6;}
else
{iImageIndex=4; iSelectedIndex=5;}
TreeNode tnDir = new TreeNode(di.Name, iImageIndex, iSelectedIndex);
tn.Nodes.Add(tnDir);
}
/*
//獲得當前目錄下的所有檔案
FileInfo[] dirFiles;
dirFiles=dirinfo.GetFiles();
int iCount=7;
foreach (FileInfo fi in dirFiles)
{
//得到每個檔案的圖示
string str=fi.FullName;
try
{
SetIcon(TreeImageList,str,false);
}
catch(Exception ex)
{ MessageBox.Show(ex.Message,"錯誤提示",0,MessageBoxIcon.Error);}
TreeNode tnDir = new TreeNode(fi.Name, iCount, iCount);
tn.Nodes.Add(tnDir);
iCount++;
}
*/
}
//*************************************************************************************
//在大圖示、小圖示、詳細列表切換時
protected virtual void ListViewAB(int iii)
{
if(iii==1)
{
LisrimageList2.ImageSize=new Size(32,32);
listView1.LargeImageList=LisrimageList2;
if(listView1.View==View.Details||listView1.View==View.SmallIcon)
{listView1.View=View.LargeIcon;}
}
else if(iii==2)
{
if(listView1.View==View.Details||listView1.View==View.LargeIcon)
{listView1.View=View.SmallIcon;}
}
else
{
if(listView1.View==View.LargeIcon||listView1.View==View.SmallIcon)
{listView1.View=View.Details;}
}
}
//*************************************************************************************
private void treeView1_BeforeExpand_1( sender, System.Windows.Forms.TreeViewCancelEventArgs e)
{
//base.OnBeforeExpand(e);
treeView1.BeginUpdate();
foreach (TreeNode tn in e.Node.Nodes)
{ AddDirectories(tn);}
treeView1.EndUpdate();
}
//*************************************************************************************
protected virtual void InitList(TreeNode tn)
{
this.statusBarPanel1.Text="正在重新整理資料夾,請稍等.....";
this.Cursor=Cursors.WaitCursor;
this.LisrimageList2.Images.Clear();
this.LisrimageList.Images.Clear();
listView1.SmallImageList=LisrimageList;
Icon ic0=myExtractIcon("%SystemRoot%system32shell32.dll",3);
LisrimageList.Images.Add(ic0);。
LisrimageList2.Images.Add(ic0);
listView1.Clear();
//設定列表框的表頭
listView1.Columns.Add("檔名",160,HorizontalAlignment.Left);
listView1.Columns.Add("檔案大小",120,HorizontalAlignment.Left);
listView1.Columns.Add("建立時間",120,HorizontalAlignment.Left);
listView1.Columns.Add("訪問時間",200,HorizontalAlignment.Left);
string strPath=tn.FullPath;
strPath=strPath.Remove(0,5);
//獲得當前目錄下的所有檔案
DirectoryInfo curDir=new DirectoryInfo(strPath);//建立目錄。
FileInfo[] dirFiles;
try
{
dirFiles=curDir.GetFiles();
}
catch { return;}
string []arrSubItem=new string[4];
//檔案的建立時間和訪問時間。
int iCount=0; int iconIndex=1;//用1,而不用0是要讓過0號圖示。
foreach(FileInfo fileInfo in dirFiles)
{
string strFileName=fileInfo.Name;
//如果不是檔案pagefile.sys
if(! strFileName.Equals("pagefile.sys"))
{
arrSubItem[0]=strFileName;
arrSubItem[1]=fileInfo.Length+" 位元組";
arrSubItem[2]=fileInfo.CreationTime.ToString();
arrSubItem[3]=fileInfo.LastAccessTime.ToString();
}
else
{ arrSubItem[1]="未知大小"; arrSubItem[2]="未知日期"; arrSubItem[3]="未知日期";}
//得到每個檔案的圖示
string str=fileInfo.FullName;
try
{
SetIcon(LisrimageList,str,false);
SetIcon(LisrimageList2,str,true);
}
catch(Exception ex)
{ MessageBox.Show(ex.Message,"錯誤提示",0,MessageBoxIcon.Error);}
//插入列表項
ListViewItem LiItem=new ListViewItem(arrSubItem,iconIndex);
listView1.Items.Insert(iCount,LiItem);
iCount++;
iconIndex++;
}
strFilePath=strPath;
textBox1.Text=strPath;
this.statusBarPanel1.Text=strPath;
this.statusBarPanel2.Text="檔案數量: " + iCount.ToString()+"個";
this.Cursor=Cursors.Arrow;
//以下是向列表框中插入目錄,不是檔案。獲得當前目錄下的各個子目錄。
int iItem=0;
DirectoryInfo Dir=new DirectoryInfo(strPath);
foreach(DirectoryInfo di in Dir.GetDirectories())
{
ListViewItem LiItem=new ListViewItem(di.Name,0);
listView1.Items.Insert(iItem,LiItem);
iItem++;
}
}
//*************************************************************************************
protected virtual void InitList2(string strName)
{
this.statusBarPanel1.Text="正在重新整理資料夾,請稍等.....";
this.Cursor=Cursors.WaitCursor;
this.LisrimageList2.Images.Clear();
this.LisrimageList.Images.Clear();
listView1.SmallImageList=LisrimageList;
Icon ic0=myExtractIcon("%SystemRoot%system32shell32.dll",3);
LisrimageList.Images.Add(ic0);
LisrimageList2.Images.Add(ic0);
listView1.Clear();
//設定列表框的表頭
listView1.Columns.Add("檔名",160,HorizontalAlignment.Left);
listView1.Columns.Add("檔案大小",120,HorizontalAlignment.Left);
listView1.Columns.Add("建立時間",120,HorizontalAlignment.Left);
listView1.Columns.Add("訪問時間",200,HorizontalAlignment.Left);
//獲得當前目錄下的所有檔案
DirectoryInfo curDir=new DirectoryInfo(strName);//建立目錄物件。
FileInfo[] dirFiles;
try
{
dirFiles=curDir.GetFiles();
}
catch { return;}
string []arrSubItem=new string[4];
//檔案的建立時間和訪問時間。
int iCount=0; int iconIndex=1;//用1,而不用0是要讓過0號圖示。
foreach(FileInfo fileInfo in dirFiles)
{
string strFileName=fileInfo.Name;
//如果不是檔案pagefile.sys
if(! strFileName.Equals("pagefile.sys"))
{
arrSubItem[0]=strFileName;
arrSubItem[1]=fileInfo.Length+" 位元組";
arrSubItem[2]=fileInfo.CreationTime.ToString();
arrSubItem[3]=fileInfo.LastAccessTime.ToString();
}
else
{ arrSubItem[1]="未知大小"; arrSubItem[2]="未知日期"; arrSubItem[3]="未知日期";}
//得到每個檔案的圖示
string str=fileInfo.FullName;
try
{
SetIcon(LisrimageList,str,false);
SetIcon(LisrimageList2,str,true);
}
catch(Exception ex)
{ MessageBox.Show(ex.Message,"錯誤提示",0,MessageBoxIcon.Error);}
//插入列表項
ListViewItem LiItem=new ListViewItem(arrSubItem,iconIndex);
listView1.Items.Insert(iCount,LiItem);
iCount++;
iconIndex++;//必須加在listView1.Items.Insert(iCount,LiItem);
}
strFilePath=strName;//把路徑賦值於全域性變數strFilePath
textBox1.Text=strName;
this.statusBarPanel2.Text="檔案數量: " + iCount.ToString()+"個";
this.Cursor=Cursors.Arrow;
//以下是向列表框中插入目錄,不是檔案。獲得當前目錄下的各個子目錄。
int iItem=0;//呼叫listView1.Items.Insert(iItem,LiItem);時用。不能使用iconIndex。
DirectoryInfo Dir=new DirectoryInfo(strName);//建立目錄物件。
foreach(DirectoryInfo di in Dir.GetDirectories())
{
ListViewItem LiItem=new ListViewItem(di.Name,0);
listView1.Items.Insert(iItem,LiItem);
iItem++;
}
}
//*************************************************************************************
private void treeView1_AfterSelect_1(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
if(e.Node.Text=="我的電腦")
{ return;}
InitList(e.Node);
}
//*************************************************************************************
private void button1_Click(object sender, System.EventArgs e)
{
this.panel1.Hide();
}
//*************************************************************************************
private void listView1_ItemActivate(object sender, System.EventArgs e)
{
string str=Path.Combine(strFilePath,listView1.FocusedItem.Text);
try
{
if(listView1.FocusedItem.SubItems.Count>1)
{ System.Diagnostics.Process.Start(str); }
else
{ InitList2(str); }
}
catch { return;}
}
//*************************************************************************************
private void menuItem3_Click(object sender, System.EventArgs e)
{
this.panel1.Visible=! panel1.Visible;
}
//*************************************************************************************
private void menuItem5_Click(object sender, System.EventArgs e)
{
ListViewAB(1);
}
//*************************************************************************************
private void menuItem6_Click(object sender, System.EventArgs e)
{
ListViewAB(2);
}
//*************************************************************************************
private void menuItem7_Click(object sender, System.EventArgs e)
{
ListViewAB(3);
}
//*************************************************************************************
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-977195/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 請教大家,java如何顯示直方圖、餅圖等等?Java直方圖
- 運用li元素進行斑馬色顯示
- 菜鳥不懂畫流程 功能圖請進
- 通達信精進3號主圖,清楚顯示支撐壓力位置原始碼原始碼
- 頁面顯示二進位制數原始據亂碼
- 直播app系統原始碼,固定速度的進度條顯示APP原始碼
- 在工作列上顯示圖示 (轉)
- 如何看原始碼?請大家討論原始碼
- 直播帶貨原始碼,背景圖片顯示鋪滿但不變形原始碼
- asp中以十六進位制顯示字串資料 (轉)字串
- c# winform下sql圖片二進位制儲存/讀取/顯示/寫入XML/讀取XML顯示C#ORMSQLXML
- 如何在請求資料時,顯示載入動畫動畫
- 請教key-value資料的顯示問題
- 請問帝國CMS圖片上傳後顯示亂碼怎麼辦
- 自定義SeekBar顯示進度
- ftp下載顯示進度FTP
- 直播系統開發,實現在進度條中顯示文字顯示進度
- 直播商城原始碼,密碼輸入框自定義顯示隱藏圖示原始碼密碼
- 直播平臺原始碼,通知欄中顯示滑動的進度條原始碼
- Win10系統檔案資源管理器看不到文字文字只顯示圖示如何解決Win10
- Win10系統下怎麼禁止資源管理器導航欄顯示兩個U盤圖示Win10
- Win10 - 開啟資源管理器顯示的不是磁碟Win10
- Win8資源管理器顯示全路徑如何設定
- android 網路請求時,顯示progrossBarAndroidROS
- 使用RestTemplate,顯示請求資訊,響應資訊REST
- 直播帶貨原始碼,商品頁面跳轉顯示白底, 新增漸變動畫原始碼動畫
- 如果線上顯示php原始碼PHP原始碼
- Win10系統下怎麼禁止資源管理器導航欄顯示兩個隨身碟圖示Win10
- Win8電腦資源管理器怎麼顯示預覽窗格?Win8資源管理器顯示預覽窗格的設定方法
- 高手請進
- c# winform旋轉顯示繪畫C#ORM
- 如何讓Win8檔案資源管理器顯示全路徑
- 字典表資料在表單中顯示的方法請教!
- win10 資源管理器百度網盤怎麼刪除_win10資源管理器顯示百度網盤圖示的刪除教程Win10
- 【菜鳥學安卓】- TextView 顯示Html 一 解決圖片顯示不了的小問題安卓TextViewHTML
- Windows 7工作列無法顯示電源圖示解析Windows
- JSF選擇標籤分行顯示請教JS
- win10資源管理器不顯示工具欄選單如何解決_win10怎麼讓資源管理器始終顯示工具欄選單Win10