无效的参数=值'15'无效'StateImageIndex'
问题描述:
我不明白这个错误,当我添加文件到我的Listviwe同时从选定的文件中的功能extarct图标,并添加extarced图标到图像列表,但是当我选择多于15个文件时,这个错误信息出现 “无效的参数=值'15'对'StateImageIndex'无效。无效的参数=值'15'无效'StateImageIndex'
这里是我的代码:
Dim ofg As New OpenFileDialog
Dim lvp As New ListViewItem
ofg.Multiselect = True
ofg.Filter = "All Files|*.*"
If ofg.ShowDialog = Windows.Forms.DialogResult.OK Then
For Each File As String In ofg.FileNames
Dim hInst As IntPtr = Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly.GetModules()(0))
Dim iIcon As Int32 = 0
Dim hIcon As IntPtr
hIcon = ExtractAssociatedIcon(hInst, File, iIcon)
ico = Icon.FromHandle(hIcon)
icondufile = ico.ToBitmap
Img.Images.Add(icondufile)
Dim C_File As New IO.FileInfo(File)
Dim ItemFile As ListViewItem = New ListViewItem(C_File.Name)
lvp = Files_List.Items.Add(ItemFile)
lvp.SubItems.Add(MD5Checksum(File))
lvp.SubItems.Add(hash_generator("sha1", File))
lvp.SubItems.Add(hash_generator("sha256", File))
lvp.SubItems.Add(GetCRC32(File))
lvp.SubItems.Add(hash_generator("sha384", File))
lvp.SubItems.Add(hash_generator("sha512", File))
lvp.SubItems.Add(C_File.FullName)
lvp.SubItems.Add(C_File.Extension)
Dim Index As Integer
lvp.StateImageIndex = lvp.Index 'The error comes from here
ItemFile = Nothing
Next
答
根据文档:
虽然在
StateImageList
属性指定的ImageList中可以包含任意数量的图像,以及StateImageIndex
属性可以设置为任何等于或低于14的值,仅索引位置0和1处的图像显示为状态图像。
那么你想用StateImageList
属性做什么?你为什么将它设置为大于14的值?
因为如果我不设置StateImageList索引没有状态图像将显示:(帮助Plz !! –
你有超过14个状态图像?根据文档,只有前两个(索引0和1)被使用所以你应该设置'StateImageIndex'为0或1,这取决于你想显示哪一个。 –
图像列表是空的,当我将文件添加到列表中时,BMP图像将被添加到图像列表'Img。 Images.Add(icondufile)“,然后当我添加更多的15个文件时出现错误信息,当我看到多少图像,我在我的图像列表中,我发现我喜欢如果我添加20个文件,我发现20个图像在图像列表中,问题是我怎么能显示更多然后14 statimage的15个文件后发生了什么预览.... https://ibb.co/n1FKYv –