vb.net - Using open file dialog and save file dialog with a list box in VB -
I will save those things that add to a list and enter the open a txt file list box. When I open a txt file, I get a one-line code and only my efforts to save empty textile files are generated. Any kind of help would be appreciated. Here is my code:
import System.IO Public Class Form1 public String Private Sub OpenToolStripMenuItem_Click (ByVal as the System.Object, ByVal e listed as System.EventArgs) OpenToolStripMenuItem.Click dim AllText handle = "" as a string, LineOfText string = "as" dim StreamToDisplay as StreamReader OpenFileDialog1.Filter = "text files (* .txt)} | * .txt "OpenFileDialog1.ShowDialog are () = DialogResult.OK then StreamToDisplay = My.Computer.FileSystem.OpenTextFileReader (OpenFileDialog1.FileName) Label1.Text = OpenFileDialog1.FileName Strymtodisep LEONDOffStream LineOftext = StreamTypeSpell Readline () 'AllText = AllText & amp; Lineofftext & amp; VbCrLf lstBox.Items.Add (listed) loop lstBox.Items.Add (AllText) Kostring () StreamToDisplay.Close () CloseToolStripMenuItem.Enabled = True OpenToolStripMenuItem.Enabled = Hold as False Exception MsgBox ( "An error has occurred." ; vbCrLf & amp; ex.Message) end Try end if end sub Private sub SaveToolStripMenuItem_Click (ByVal as the System.Object, ByVal e System.EventArgs) as handle SaveToolStripMenuItem.Click SaveFileDialog1.Filter = "text files (* .txt) | * .txt "If SaveFileDialog1.ShowDialog () = DialogResult.OK then My.Computer.FileSystem.WriteAllText (SaveFileDialog1.FileName, lstBox.Items.ToString (), false) end If end sub Private sub Close Curtolst Ripmenuitmklik (ByVal system as the sender. Object, ByVal systems such as e. Aventargs) Krentulstripmenuitm off. Click lstBox.Items.Clear () Label1.Text = "" CloseToolStripMenuItem.Enabled = False OpenToolStripMenuItem.Enabled = True End Sub Private Sub btnAdd_Click (ByVal sender system. Object, ByVal as systems such as e. EventArgs) handles btnAdd.Click Dim as immediate string = list = InputBox (prompt) lstBox.Items.Add (listed) .ToString () End sub Private sub btnRemove_Click (ByVal as the System.Object, as ByVal e System.EventArgs In the "Hand to Add Objects Here" click with "BtnRemove.lstBox" Amit. Remove (. Selected favored) Termination
Here is a simple example is: the
- before the
ListBox - in saves in a file
- loads them into a file and
ListBox Code:
Import system. IO as the object public class Form 1 Private Sub button AddItem_Click (, e EventArgs) Handles ButtonAddItem.Click ListBox1.Items.Add (DateTime.Now.Ticks) End Sub private Sub ButtonSave_Click (this object, e as EventArgs) handles ButtonSave.Click so SaveFileDialog1.ShowDialog () = DialogResult.OK using either writer = new StreamWriter (SaveFileDialog1.FileName) x1.Items writer.WriteLine (o as object ListBo for each ) Using the other end from the end, then End Sub personal sub ButtonLoad_Click (as the object, in the form of e EventArgs) Handle ButtonLoad.Click so OpenFileDialog1.ShowDialog () = DialogResult.OK then dim lines = File.ReadAllLines (OpenFileDialog1.FileName) ListBox1.Items.Clear () ListBox1.Items.AddRange (rows) End End End End End Class
Comments
Post a Comment