VB.net用图像保存/加载Listview项 [英] VB.net Save/Load Listview Items with images
问题描述
您好,我有一个包含图片的Listview,我需要在关闭表单时保存它,并在表单启动时加载它.
Hello, i have a Listview with images and i need to save it when i close the form, and load it when the form starts.
使用以下代码加载即时消息:
For load im using this code:
ListView2.View = View.List
If IO.File.Exists(myCoolFile) Then '// check if file exists.
Dim myCoolFileLines() As String = IO.File.ReadAllLines(myCoolFile) '// load your file as a string array.
For Each line As String In myCoolFileLines '// loop thru array list.
Dim lineArray() As String = line.Split("#") '// separate by "#" character.
Dim newItem As New ListViewItem(lineArray(0)) '// add text Item.
ListView2.Items.Add(newItem) '// add Item to ListView.
Next
End If
使用此代码保存列表视图项:
For save listview items im using this code:
Dim myWriter As New IO.StreamWriter(myCoolFile)
For Each myItem As ListViewItem In ListView2.Items
myWriter.WriteLine(myItem.Text) '// write Item and SubItem.
Next
myWriter.Close()
对于使用以下命令创建商品:
And for create items im using this:
Dim item As New ListViewItem
item.Text = "Maldita Castilla"
ImageList1.Images.Add("Image0", Image.FromFile("C:\Program Files (x86)\xylithed\covers\maldita_castilla.jpg"))
item.ImageKey = "Image0"
ListViewAdventure.Items.Add(item)
¿我如何保存"Image.FromFile"?到txt文件并加载吗?
¿How i can save the "Image.FromFile" to the txt file and load it too?
推荐答案
用于保存和加载的代码似乎不匹配.在保存期间被放置?
The code for saving and for loading do not seem to match... where does the "#" get placed during saving?
使用中间对象存储数据可能会容易得多.您想要一个具有每个字段值一个属性的类,再加上一个用于存储图像位置或关联键的属性.
This would likely be much easier with an intermediary object to store the data. You'd want a class with one property for each field value plus one property to store the image location or associated key.
但是,如果要从代码开始填充列表视图,那么要保存什么呢?您能否在程序中解释列表视图的用途,并描述用户打算如何使用它?
But if you are populating the listview from code to begin with, what is there to save? Could you please explain the listview's purpose in the program and describe how the user is meant to work with it?
这篇关于VB.net用图像保存/加载Listview项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!