martijn098
Gebruiker
- Lid geworden
- 18 feb 2012
- Berichten
- 341
Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
Try
If File.Exists(Application.StartupPath & "\save.txt") Then
Dim SR As StreamReader, Temp, Item As String, i As Integer
If (File.Exists(Application.StartupPath + "\save.txt")) Then
SR = File.OpenText(Application.StartupPath & "\save.txt")
Temp = SR.ReadToEnd()
SR.Close()
For i = 0 To Temp.Length - 1
If (Temp.Substring(i, 1) <> "-") Then
Item += Temp.Substring(i, 1)
Else
ListBox1.Items.Add(Item)
Item = String.Empty
End If
Next
ListBox1.Items.Add(Item)
End If
End If
If File.Exists(Application.StartupPath + "\save.txt") Then
My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\save.txt")
End If
If ListBox1.Items.Count > 0 Then
Dim SW As StreamWriter, i As Integer, Temp As String
SW = IO.File.CreateText(Application.StartupPath + "\save.txt")
For i = 0 To ListBox1.Items.Count - 1
If (i <> 0) Then
Temp = Temp + "-" + ListBox1.Items.Item(i)
Else
Temp = ListBox1.Items.Item(0)
End If
Next
SW.Write(Temp)
SW.Flush()
SW.Close()
End If
Application.StartupPath & "\save.txt"
Path.Combine(Application.StartupPath, "file.txt")
public partial class MainView : Form
{
private readonly string _root = Application.StartupPath;
private string _file = "data.txt";
public MainView()
{
InitializeComponent();
Load();
}
private void Load()
{
string path = Path.Combine(_root, _file);
lstItems.Items.Clear();
if (File.Exists(path))
{
string[] lines = File.ReadAllLines(path);
foreach (var line in lines)
{
lstItems.Items.Add(line);
}
}
}
private void Save()
{
string path = Path.Combine(_root, _file);
var items = new List<string>();
foreach (var item in lstItems.Items)
{
items.Add(item.ToString());
}
File.WriteAllLines(path, items.ToArray());
}
//events
private void MainView_FormClosing(object sender, FormClosingEventArgs e)
{
Save();
}
private void btnAdd_Click(object sender, EventArgs e)
{
lstItems.Items.Add(txtItem.Text);
txtItem.Clear();
txtItem.Focus();
}
}
IO.File.WriteAllLines(path, Items.ToArray)
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.