帮助将png文件添加到列表视图框中
我有以下代码,其中我连接到远程计算机以获取已安装软件的列表.该代码工作正常,但非常空白,我想通过在特定名称旁边添加一个png图标来为其增添趣味.现在我已经通过删除我想要链接到特殊图标的代码在底部用空的if语句测试了代码,只是不知道如何在StrName旁边添加png图标.
我尝试添加ListView1.Items(0).ImageIndex = 1,但这对我没有用.
如果有人可以帮助,那将是很好.我整天都在看这本书,我认为我需要其他人的注意.
I have the below code where i m connecting to a remote computer to get a list of installed software. The code works fine but its very blan and i want to spice it up with adding a png icon next to specific names. Now i have tested the code with the empty if statement at the bottom by deleting the ones i want to have a special icon linked to i just dont know how i would add a png icon next to StrName.
I have tried adding ListView1.Items(0).ImageIndex = 1 but this didnt work for me.
If someone could help that would be great. I have been looking at this all day and i think i need someone else eyes on it.
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Dim objLocator, objService, objRegistry, arrIdentityCode, strIdentityCode, objShell
Dim strRegIdentityCodes As String
objLocator = CreateObject("WbemScripting.SWbemLocator")
Dim strComputer As String = Application.Machine_Name_Textbox_Header.Text
If Application.Machine_Name_Textbox_Header.Text = "" Then
strComputer = "127.0.0.1"
End If
Try
objService = objLocator.ConnectServer(strComputer, "Root\Default")
objService.Security_.impersonationlevel = 3
objRegistry = objService.Get("StdRegProv")
Catch ex As Exception
End Try
strRegIdentityCodes = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Const HKLM = &H80000002
Dim strRegIdentityInfo, strDisplayName, strDisplayVersion, strInstallDate, strUninstallString, strPublisher
objRegistry.EnumKey(HKLM, strRegIdentityCodes, arrIdentityCode)
objShell = CreateObject("WScript.Shell")
Dim strName As String
For Each strIdentityCode In arrIdentityCode
Try
strRegIdentityInfo = "HKEY_LOCAL_MACHINE\" & strRegIdentityCodes & "\" & strIdentityCode & "\"
strDisplayName = objShell.RegRead(strRegIdentityInfo & "DisplayName")
strDisplayVersion = objShell.RegRead(strRegIdentityInfo & "DisplayVersion")
strInstallDate = InstallDate(objShell.RegRead(strRegIdentityInfo & "InstallDate"))
strUninstallString = objShell.RegRead(strRegIdentityInfo & "UninstallString")
strPublisher = objShell.RegRead(strRegIdentityInfo & "Publisher")
strName = strDisplayName
Dim item As ListViewItem = New ListViewItem(strName)
item.SubItems.Add(strDisplayVersion)
item.SubItems.Add(strInstallDate)
item.SubItems.Add(strPublisher)
item.SubItems.Add(strUninstallString)
item.SubItems.Add(strRegIdentityInfo)
ListView1.Items.Add(item)
If (strName.StartsWith("Hotfix") Or strName.StartsWith("Security") Or strName.StartsWith("Update")) Then
End If
Catch ex As Exception
End Try
Next
End Sub
在WinForm中,您需要从ListBox继承一个新控件.在您的解决方案中创建一个类型为"Windows控制库"的新项目.这是代码文件:
In WinForm, you need to inherit a new control from ListBox. Create a new project in your solution, of the type "Windows Control Library". Here is the code file:
public partial class ListBoxWithBg : ListBox
{
Image image;
Brush brush, selectedBrush;
public ListBoxWithBg(String ImageFile)
{
InitializeComponent();
this.DrawMode = DrawMode.OwnerDrawVariable;
this.DrawItem += new DrawItemEventHandler(ListBoxWithBg_DrawItem);
this.image = Image.FromFile(ImageFile);
this.brush = new SolidBrush(Color.Black);
this.selectedBrush = new SolidBrush(Color.White);
}
}