i want to know how to do when the form is closed, the current contents of the listbox will be stored in the bookmarks textfile (called bookmarks.txt). If a file error occurs, display a messagebox specifying the error.
public Form1()
{
InitializeComponent();
}
private void btn_go_Click(object sender, EventArgs e)
{
wBrowser.Navigate(tbx_website.Text);
}
private void btn_bookmark_Click(object sender, EventArgs e)
{
//Add the url to the listbox
LBlist.Items.Add(tbx_website.Text);
if (LBlist.Items.Count == 0)
{
btn_delete.Enabled = false;
}
}
private void btn_delete_Click(object sender, EventArgs e)
{
// The Delete button was clicked
int i_delete = LBlist.SelectedIndex;
try
{
// Remove the item in the List.
LBlist.Items.RemoveAt(i_delete);
}
catch
{
}
}
private void listbox_DoubleClick(object sender, EventArgs e)
{
tbx_website.Text = LBlist.SelectedItem.ToString();
}
private void wBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
tbx_website.Text = wBrowser.Url.ToString();
}
private void LBlist_SelectedIndexChanged(object sender, EventArgs e)
{
btn_delete.Enabled = (LBlist.Items.Count > 0);
}
private void Form1_Load(object sender, EventArgs e)
{
btn_delete.Enabled = false;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
StreamWriter sw_file;
string s_bmfile = LBlist.Items.ToString();
sw_file = new StreamWriter("bookmarks.txt");
sw_file.Write(s_bmfile);
sw_file.Close();
}