在winForm下编程时,做资源管理器浏览本地文件的时候,用ListView控件加载文件,
可以根据文件类型来判断item的图标,具体代码如下:
可以根据文件类型来判断item的图标,具体代码如下:
1
using System;
2
using System.Drawing;
3
using System.Windows.Forms;
4![](/Images/OutliningIndicators/None.gif)
5
namespace YJDSoft.Control.Data.LocalDataExplorer
6
{
7
/// <summary>
8
/// ImageIconManage 的摘要说明。
9
/// </summary>
10
public class ImageIconManage
11
{
12
private System.Windows.Forms.ImageList m_SmallImageList;
13
private System.Windows.Forms.ImageList m_LargeImageList;
14
//private System.IntPtr m_FormHandle;
15
private int IconIndex = 0 ;
16
/// <summary>
17
/// 图表管理类
18
/// </summary>
19
/// <param name="SmallImageList">小图标集合的list</param>
20
/// <param name="LargeImageList">大图标集合的list</param>
21
public ImageIconManage(System.Windows.Forms.ImageList SmallImageList,System.Windows.Forms.ImageList LargeImageList)
22
{
23
//
24
// TODO: 在此处添加构造函数逻辑
25
//
26
m_SmallImageList = SmallImageList;
27
m_LargeImageList = LargeImageList;
28
//m_FormHandle = FormHandle;
29
m_LargeImageList.ImageSize = new Size(32,32);
30![](/Images/OutliningIndicators/InBlock.gif)
31
this.m_LargeImageList.Images.Clear();
32
this.m_SmallImageList.Images.Clear();
33
Icon ic0=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",3);
34
m_LargeImageList.Images.Add(ic0);
35
m_SmallImageList.Images.Add(ic0);
36
}
37
/// <summary>
38
/// 得到该文件对应的图标(包括大图标,小图标)
39
/// </summary>
40
/// <param name="FileNameOrExtension">文件的全路径或者文件的带点扩展名(如: .Dll)</param>
41
/// <returns>返回该文件或扩展名的图标在SmallImageList或LargeImageList里的索引值</returns>
42
public int FileBindingIcon(string FileNameOrExtension)
43
{
44
try
45
{
46
SetIcon(m_SmallImageList,FileNameOrExtension,false);//得到小图标平铺
47
SetIcon(m_LargeImageList,FileNameOrExtension,true);//得到大图标平铺
48
return IconIndex = IconIndex + 1;
49
}
50
catch(Exception ex)
51
{
52
MessageBox.Show(ex.Message,"错误提示",0,MessageBoxIcon.Error);
53
return -1;
54
}
55
}
56
/// <summary>
57
/// 得的目录的图标的索引值
58
/// </summary>
59
public int GetFolderIcon
60
{
61
get
62
{
63
return 0; //目录图标的索引值默认为0
64
}
65
}
66![](/Images/OutliningIndicators/InBlock.gif)
67
用API函数调用取的文件对应的图标的所有方法
139![](/Images/OutliningIndicators/InBlock.gif)
140
}
141
}
142![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
7
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/InBlock.gif)
34
![](/Images/OutliningIndicators/InBlock.gif)
35
![](/Images/OutliningIndicators/InBlock.gif)
36
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
37
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
38
![](/Images/OutliningIndicators/InBlock.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/InBlock.gif)
41
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
42
![](/Images/OutliningIndicators/InBlock.gif)
43
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
44
![](/Images/OutliningIndicators/InBlock.gif)
45
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
46
![](/Images/OutliningIndicators/InBlock.gif)
47
![](/Images/OutliningIndicators/InBlock.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
50
![](/Images/OutliningIndicators/InBlock.gif)
51
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
52
![](/Images/OutliningIndicators/InBlock.gif)
53
![](/Images/OutliningIndicators/InBlock.gif)
54
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
55
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
56
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
58
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
59
![](/Images/OutliningIndicators/InBlock.gif)
60
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
61
![](/Images/OutliningIndicators/InBlock.gif)
62
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
63
![](/Images/OutliningIndicators/InBlock.gif)
64
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
65
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
66
![](/Images/OutliningIndicators/InBlock.gif)
67
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
139
![](/Images/OutliningIndicators/InBlock.gif)
140
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
141
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
142
![](/Images/OutliningIndicators/None.gif)