前阵子做.NET2003下的开发, 有些琐碎的细节记录在了网易博客里, 现在搬家过来啦.
1. 将一些代码分类管理:
#region [类别名]
...//内容
#endregion
2. 列举硬盘驱动器:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
//列举驱动器
2
private void EnumDriver(TreeNode node)
3![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
4
//String drv;
5
if (node.Nodes.Count == 0)
6![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
7
foreach(String drv in System.IO.Directory.GetLogicalDrives())
8![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
9
treeView1.SelectedNode = node;
10
TreeNode tmpNode = new TreeNode();
11
tmpNode.Text = drv.Substring(0, drv.Length - 1);
12
tmpNode.Tag = drv;
13
tmpNode.ImageIndex = 1;
14
tmpNode.SelectedImageIndex = 1;
15![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
treeView1.SelectedNode.Nodes.Add(tmpNode);
17
treeView1.SelectedNode.LastNode.EnsureVisible();
18
}
19
}
20
}
21![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3. 列举子文件夹
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
//列举子文件夹
2
private void EnumDir(TreeNode node)
3![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
4
treeView1.SelectedNode = node;
5
String DirectoryPath = node.Tag.ToString();
6
if (node.Nodes.Count == 0)
7![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
8
if (DirectoryPath.Substring(DirectoryPath.Length - 1) != "\\")
9![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
10
DirectoryPath += "\\";
11
}
12
try
13![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
14
foreach (String dir in System.IO.Directory.GetDirectories(DirectoryPath))
15![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
16
TreeNode tmpNode = new TreeNode();
17
tmpNode.Text = dir.Substring(dir.LastIndexOf("\\") + 1);
18
tmpNode.Tag = dir;
19
tmpNode.ImageIndex = 2;
20
tmpNode.SelectedImageIndex = 3;
21
treeView1.SelectedNode.Nodes.Add(tmpNode);
22
treeView1.SelectedNode.LastNode.EnsureVisible();
23
}
24
}
25
catch( System.Exception ex)
26![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
27
MessageBox.Show(ex.Message);
28
}
29
}
30
EnumFile(node);//列举文件
31
}
4. 列举文件
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
//列举文件
2
private void EnumFile(TreeNode node)
3![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
4
String strFileName;
5
String DirectoryPath = node.Tag.ToString();
6
if (DirectoryPath.Substring(DirectoryPath.Length - 1) != "\\")
7![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
8
DirectoryPath += "\\";
9
}
10
try
11![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
12
listView1.Items.Clear();
13
listBox1.Items.Clear();
14
ListViewItem lbi;
15
foreach (String tmpFile in System.IO.Directory.GetFiles(DirectoryPath))
16![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
17
strFileName = System.IO.Path.GetFileName(tmpFile);
18
strFileName = strFileName.Substring(strFileName.Length - 3, 3);
19
if (strFileName.ToLower().Equals("bmp"))
20![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
21
lbi = new ListViewItem(System.IO.Path.GetFileName(tmpFile));
22
//lbi.SubItems.Add(File.GetLastAccessTime(tmpFile));
23
listView1.Items.Add(lbi);
24
listBox1.Items.Add(System.IO.Path.GetFileName(tmpFile));
25
}
26
}
27
strPath = DirectoryPath;
28
}
29
catch(System.Exception ex)
30![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
31
MessageBox.Show(ex.Message);
32
}
33
}
5. .NET没有能够生成gif图片的类, 只能自己写, 找到一个第三方的东西(Gif.Components)
下载地址:http://www.codeproject.com/KB/GDI-plus/NGif.aspx
使用方法:
将此动态链接库文件引入到工程中, 并使用语句using Gif.Components;引入到使用处.
然后这样使用:
AnimatedGifEncoder ee = new AnimatedGifEncoder();
ee.Start( /*在此填入要生成gif文件的地址文件名全路径*/ );
ee.SetDelay( /*在此填入gif动画的每帧间隔时间,毫秒级*/ );
ee.SetRepeat(/*在此填入是否使gif动画重复播放, 0为重复, -1为不重复*/);
for ( /*填入循环条件*/ )
{
ee.AddFrame( Image.FromFile( /*在此填入要生成gif的原图片文件的全路径*/ ) );
}
ee.Finish();//结束gif图片生成.