03-09-14, 01:34 PM
السلام عليكم،
كود :
Public Class Form1
Dim img As New ImageList
Dim indices As New Dictionary(Of Integer, Integer)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
With img
.ColorDepth = ColorDepth.Depth32Bit
.ImageSize = New Size(16, 16)
End With
With ListView1
.Clear()
.View = View.Details
.Columns.Add("Process name", 250)
.Columns.Add("ProcessID", 80)
.GridLines = True
.SmallImageList = img
End With
For x As Integer = 0 To Process.GetProcesses.Length - 1
Dim p As Process = Process.GetProcesses()(x)
With ListView1.Items.Add(p.ProcessName)
Dim pid = p.Id
.SubItems.Add(pid)
Try
Dim ico As Icon = Icon.ExtractAssociatedIcon(p.MainModule.FileName)
img.Images.Add(pid.ToString, ico)
.ImageKey = pid.ToString
Catch
Finally
indices.Add(x, img.Images.Count - 1)
End Try
End With
Next
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
PictureBox1.Image = img.Images(indices(ListView1.FocusedItem.Index))
End Sub
End Class
