如何将文件扩展名和系统图标关联在一起?

mfjustlove 2006-09-21 10:30:28
在ListView中我取得一些文件信息,我想通过文件的扩展名
在ListView中添加与扩展名相对应的文件类型的图标,该怎么做?
请前辈们指点,谢谢。
...全文
650 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
LoveMango 2007-04-26
  • 打赏
  • 举报
回复
mark
yuanzhihua520 2006-11-07
  • 打赏
  • 举报
回复
up
mfjustlove 2006-09-22
  • 打赏
  • 举报
回复
有这么多资料差不多了。谢谢各位
angel_bear 2006-09-22
  • 打赏
  • 举报
回复
mark
zzmwmh 2006-09-22
  • 打赏
  • 举报
回复
把取到的图标加入到和你的listView绑定的imageList中就行了,要想图标好看点的话,要用32位颜色.我还没得到过别人给的分呢...
zzmwmh 2006-09-22
  • 打赏
  • 举报
回复
我以前也找过,把我找到并写好的给你吧

[DllImport("Shell32.dll")]
static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
/// <summary>
/// 要用到的一个结构
/// </summary>
struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
public char szDisplayName;
public char szTypeName;
}

/// <summary>
/// 从文件扩展名得到小图标
/// </summary>
/// <param name="FileName">文件名或文件扩展名</param>
/// <returns>图标</returns>
static public Icon SetIcon(string FileName)
{
SHFILEINFO fi = new SHFILEINFO();
Icon ic = null;
int iTotal = (int)SHGetFileInfo(FileName, 100, ref fi, 0, 273);//从文件扩展名得到小图标
//SHGFI_ICON+SHGFI_USEFILEATTRIBUTES+SmallIcon
//273=十六进100 +10 +1
//如果要大图标,改为272
if (iTotal > 0)
{
ic = Icon.FromHandle(fi.hIcon);
}
return ic;
}
mfjustlove 2006-09-22
  • 打赏
  • 举报
回复
啊,还要注册表,这个对我来说现在有点麻烦的哇
qhfrose 2006-09-22
  • 打赏
  • 举报
回复
应该是从注册表中读取图标的路径,然后显示出来。
manasheep 2006-09-22
  • 打赏
  • 举报
回复
我也挺想了解这个的
RexZheng 2006-09-22
  • 打赏
  • 举报
回复
关注
mfjustlove 2006-09-22
  • 打赏
  • 举报
回复
不过还是谢谢,
没有别的更好的方法了吗?
真相重于对错 2006-09-22
  • 打赏
  • 举报
回复
ms-help://MS.MSDNQTR.2003FEB.2052/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/icon.htm
mfjustlove 2006-09-22
  • 打赏
  • 举报
回复
那QQ的群共享里面的也是自己建的类似ImageList?
可是它对系统那么多的文件类型都能一一对应上阿,
不过是新的文件类型还久的,那么阿,做一个ImageList
用Switch语句不是很大很繁琐。
Knight94 2006-09-22
  • 打赏
  • 举报
回复
调用API:SHGetFileInfo,参看
http://www.pinvoke.net/default.aspx/shell32/SHGetFileInfo.html
jackyped 2006-09-22
  • 打赏
  • 举报
回复
图标是你自己设置的
先建2个imagelist,将listview的largeimagelist设置为1,smallimagelist设置为2,然后

switch 扩展名
case ".txt":
listviewitem.imageindex = 0;
case ".cs"
listviewitem.imageindex = 1;
....
hy_lihuan 2006-09-21
  • 打赏
  • 举报
回复
用程序控制阿,什么类型的对应什么图表阿,if就能搞定阿。
如果你不太清楚有多少种类型,那可能就要做一个截面让用户自己对应了

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧