使用图像保存并加载ListView项目

时间:2015-03-29 14:19:59

标签: vb.net listview save load

我正在VB.net中编写应用程序,我正在使用ListView来存储一些数据。我需要在表单关闭时保存此项目列表及其图像,并在再次打开表单时再次加载它。

Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Dim myWriter As New IO.StreamWriter(myCoolFile)
    For Each myItem As ListViewItem In ListView2.Items
        myWriter.WriteLine(myItem.Text) '// save item text.
    Next
    myWriter.Close()
End Sub

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   

¿保存和加载此列表及其图像的最佳方法是什么?,这是我用于创建项目的代码:

Dim item1 As New ListViewItem
            item1.Text = My.Settings.name_download
            ImageList2.Images.Add("Image1", Image.FromFile("C:\Program Files (x86)\xylithed\covers\maldita_castilla2.png"))
            item1.ImageKey = "Image1"
            ListView2.Items.Add(item1)

我需要保存“Image.FromFile”并加载它。

0 个答案:

没有答案