永发信息网

c#中如何获得文件的图标,我想做一个拖拽文件得到图标的程序,,大侠们给点资料

答案:2  悬赏:40  手机版
解决时间 2021-02-11 20:23
  • 提问者网友:轻浮
  • 2021-02-11 09:04
http://blog.csdn.net/xuzhiqiang1010/archive/2009/11/23/4859264.aspx
找到一个资料,谢谢楼下的那位
最佳答案
  • 五星知识达人网友:長槍戰八方
  • 2021-02-11 10:33
自定义一个方法:
public static System.Drawing.Icon GetFileIcon(string name, IconSize size,bool linkOverlay)
{
Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO();
uint flags = Shell32.SHGFI_ICON | Shell32.SHGFI_USEFILEATTRIBUTES;
if (true == linkOverlay) flags += Shell32.SHGFI_LINKOVERLAY;

if (IconSize.Small == size)
{
flags += Shell32.SHGFI_SMALLICON ;
}
else
{
flags += Shell32.SHGFI_LARGEICON ;
}
Shell32.SHGetFileInfo( name,Shell32.FILE_ATTRIBUTE_NORMAL,ref shfi,(uint) System.Runtime.InteropServices.Marshal.SizeOf(shfi),flags );
// Copy (clone) the returned icon to a new object, thus allowing us to clean-up properly
System.Drawing.Icon icon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shfi.hIcon).Clone();
User32.DestroyIcon( shfi.hIcon ); // Cleanup
return icon;
}
为按钮添加一个点击事件:
private void cmdFileSmall_Click(object sender, System.EventArgs e)
{
OpenFileDialog dlgOpenFile = new OpenFileDialog();
if(dlgOpenFile.ShowDialog() == DialogResult.OK)
{
this.Icon=GetFileIcon(dlgOpenFile.FileName, IconSize.Small, false);
}
}
全部回答
  • 1楼网友:旧脸谱
  • 2021-02-11 11:36

你是只知其然不知其所以然,上面你转化的array就是一个数组,getvalue(0)取了第一个

string[] ss = e.data.getdata(dataformats.filedrop,false) as string[]; foreach(string s in ss) listbox1.items.add(s);
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯