如何在系统中获取驱动器的图标,并在列表视图框中添加这些图标,并在vb.net中添加相应的驱动器号。 [英] How to get the icons of drives in a system and add those icon in listview box with corrosponding drive letters in vb.net.

查看:91
本文介绍了如何在系统中获取驱动器的图标,并在列表视图框中添加这些图标,并在vb.net中添加相应的驱动器号。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个类似于文件浏览器的程序,所以我正在编写代码以在列表视图框中显示带有驱动器图标的驱动器号,但我不知道如何将它们的图标放在列表视图框中。 br />
我使用的是Microsoft visual basic 2010 express。



我尝试了什么:



I am trying to make a program similar to file explorer so i am writing code to show drive letters with their drive icon in a list view box but i don't know how to put their icon in the list view box.
I am using Microsoft visual basic 2010 express.

What I have tried:

Imports System
Imports System.IO

Public Class Test


    Private Sub Test_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim drives As String() = System.IO.Directory.GetLogicalDrives()
        For Each drive As String In drives
            ListView1.Items.Add(drive)
            'I need to add the icon of the drive
        Next

    End Sub
End Class

推荐答案

本地驱动器只有一个相同的图标。它可以可以使用 Icon.ExtractAssociatedIcon方法(字符串)(System.Drawing) [ ^ ]通过一个没有路径的驱动器字符串,如C:。



要将图标添加到列表视图,您需要创建 ImageList ,将图标添加到该列表,并设置用于添加的相应密钥添加列表视图项时图像列表的图标。 AC#示例可以在如何:提取与Windows窗体中的文件关联的图标| Microsoft Docs [ ^ ](旧版本的VB.Net代码: Gewusst wie:Extrahieren eines mit einerDateiverknüpftenWindowsForms中的符号 [ ^ ];忽略德语标题,内容为英文)。
There is only one identical icon for local drives. It can Drive icons can be retrieved using the Icon.ExtractAssociatedIcon Method (String) (System.Drawing)[^] by passing a drive string without path like "C:".

To add icons to a list view, you need to create an ImageList, add the icons to that list, and set the corresponding key that has been used to add the icon to the image list when adding the list view item. A C# example can be found at How to: Extract the Icon Associated with a File in Windows Forms | Microsoft Docs[^] (old version with VB.Net code: Gewusst wie: Extrahieren eines mit einer Datei verknüpften Symbols in Windows Forms[^]; ignore the German title, the content is English).


不要只是下载并复制粘贴代码。首先运行示例检查输出然后调试,看看源代码中发生了什么,然后尝试与您的方法类似地实现。



实施带有ListView的常见文件系统浏览器 [ ^ ]
Don't just download and copy paste the code.First run the sample check the output then debug and see what is happening in the source code then try to implement similarly with your approach.

Implementing a common File system browser with a ListView[^]


这篇关于如何在系统中获取驱动器的图标,并在列表视图框中添加这些图标,并在vb.net中添加相应的驱动器号。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆