是否有任何窗体控件显示带有图标的驱动器号列表?驱动器选择框中带有窗口图标的图标
2
A
回答
3
不,但我相信你可以做到这一点,不应该太棘手,无论是使用TreeView,或者如果你只是喜欢列表,然后你可以使用ListView。
的代码来获取驱动器将与此类似:
//Get all Drives
DriveInfo[] ListAllDrives = DriveInfo.GetDrives();
要确定一个ListViewItem或TreeViewNodes你可以做这样的事情的图标:
foreach (DriveInfo Drive in ListAllDrives)
{
//Create ListViewItem, give name etc.
ListViewItem NewItem = new ListViewItem();
NewItem.Text = Drive.Name;
//Check type and get icon required.
if (Drive.DriveType.Removable)
{
//Set Icon as Removable Icon
}
//else if (Drive Type is other... etc. etc.)
}
0
如果您愿意为此付款,则可以查看http://viewpack.qarchive.org/。
我不知道任何自由控件。
0
我终于想出了我自己的控制。
我填一个ListView与驱动如下:
listView1.SmallImageList = new ImageList();
var drives = DriveInfo.GetDrives()
.Where(x => x.DriveType == DriveType.Removable)
.Select(x => x.Name.Replace("\\",""));
foreach (var driveName in drives)
{
listView1.SmallImageList.Images.Add(driveName, GetFileIcon(driveName));
listView1.Items.Add(driveName, driveName);
}
哪里GetFileIcon是我自己的方法调用的SHGetFileInfo:
IntPtr hImgSmall; //the handle to the system image list
SHFILEINFO shinfo = new SHFILEINFO();
//Use this to get the small Icon
hImgSmall = Win32.SHGetFileInfo(fileName, 0, ref shinfo,
(uint)Marshal.SizeOf(shinfo),
Win32.SHGFI_ICON |
Win32.SHGFI_SMALLICON);
return System.Drawing.Icon.FromHandle(shinfo.hIcon);
的Win32类原样复制形式this site,看起来如下:
[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public IntPtr iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
};
class Win32
{
public const uint SHGFI_ICON = 0x100;
public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
public const uint SHGFI_SMALLICON = 0x1; // 'Small icon
[DllImport("shell32.dll")]
public static extern IntPtr SHGetFileInfo(string pszPath,
uint dwFileAttributes,
ref SHFILEINFO psfi,
uint cbSizeFileInfo,
uint uFlags);
}
我希望它能帮助别人。
相关问题
- 1. 带有箭头图标的窗口拖动
- 2. 从滚动视图中选择图标
- 3. GLFW窗口图标
- 4. 使标题图标成为浏览器窗口的拖动源
- 5. Mobile Safari中的新窗口图标是标准图标吗?
- 6. 在Android MapView中选择带标线的地图标记?
- 7. 标签栏图标选择的图像
- 8. 带有复选框的Flex中的标签图像
- 9. 在图标选择器中使用Unicode图标
- 10. TaskDialog - 窗口上没有图标10
- 11. 问题与所有窗口图标
- 12. PyQt4中Exe的窗口图标
- 13. Java2d:拖动鼠标时显示选择窗口的选项
- 14. 在进程中移动带有标题栏的Python GTK3窗口
- 15. SVG - 从窗口坐标到视图框坐标
- 16. 如何显示没有图标的文档窗口的标题?
- 17. 选择部署目标窗口
- 18. CSS复选框+标签下带有ul/li的图像
- 19. 带有图标的QTableView行
- 20. 带有图标的tabhost
- 21. 如何在应用程序任务栏图标上选择“关闭所有窗口”时关闭所有窗口?
- 22. 翻译角度带选择图标标签
- 23. 为XNA窗口设置窗体图标?
- 24. 在托盘窗口中隐藏图标
- 25. 从WPF窗口中删除图标
- 26. 带有复选框的网格视图在标签中附加选定的值
- 27. 带附件视图的隐藏窗口标题
- 28. Android微调,选择器图标位置
- 29. 引导日期选择器图标
- 30. Grails g:为每个选项选择带小图片的标签
只需注意,使用shell32.dll时要小心,它可能会改变(你知道微软是什么样的!),我问了一个关于在这里使用它们的图标的问题http://stackoverflow.com/questions/949196/加载图标从shell32-dll-win32-handle-is-valid-or-is-the-wrong-type – ThePower 2009-08-05 12:42:59