Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
SaveListBox(ListBox1, Application.StartupPath & "\Fichier.txt")
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
LoadListBox(ListBox1, Application.StartupPath & "\Fichier.txt")
End Sub
Public Sub LoadListBox(ByRef oLst As System.Windows.Forms.ListBox, ByVal sPath As String)
Dim sr As New System.IO.StreamReader(sPath)
Do While Not sr.EndOfStream
oLst.Items.Add(sr.ReadLine())
Loop
sr.Close()
End Sub
Public Sub SaveListBox(ByRef oLst As System.Windows.Forms.ListBox, ByVal sPath As String)
Dim sw As New System.IO.StreamWriter(sPath)
For Each o As Object In oLst.Items
sw.WriteLine(o.ToString)
Next
sw.Close()
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Form1
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
SaveListBox(ComboBox1, Application.StartupPath & "\Fichier.txt")
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
LoadListBox(ComboBox1, Application.StartupPath & "\Fichier.txt")
End Sub
Public Sub LoadListBox(ByRef oLst As System.Windows.Forms.ComboBox, ByVal sPath As String)
Dim sr As New System.IO.StreamReader(sPath)
Do While Not sr.EndOfStream
oLst.Items.Add(sr.ReadLine())
Loop
sr.Close()
End Sub
Public Sub SaveListBox(ByRef oLst As System.Windows.Forms.ComboBox, ByVal sPath As String)
Dim sw As New System.IO.StreamWriter(sPath)
For Each o As Object In oLst.Items
sw.WriteLine(o.ToString)
Next
sw.Close()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ComboBox1.Items.Add(TextBox1.Text)
End Sub
End Class