//when the add to favourites is clicked from the toolbar private void addToFavouritesToolStripMenuItem_Click(object sender, EventArgs e) { AddToFavourites frmFavourites = new AddToFavourites(); //remove any spaces from the url and save the url to the class's object frmFavourites.setMyURL(this.urltextbox.Text.Trim()); //show the dialog box for Add to Favourites frmFavourites.ShowDialog(); //refresh the favourites so that hey get updated reloadFavourites(); }
void ddMenu_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { //save the index of the favourite menu item in the design int favindex = this.favortiToolStripMenuItem.DropDownItems.IndexOf(e.ClickedItem.OwnerItem); //save the text of the clicked menu item string subMenuText = e.ClickedItem.Text; //if the menu item clicked is Open if (subMenuText == "Open") { try { //open the favourites text file and read the line number from favindex StreamReader rdr = new StreamReader("favourites.txt"); string line = rdr.ReadToEnd().Split(new string[]{"\r\n"},StringSplitOptions.RemoveEmptyEntries)[favindex]; //split that line into two further parts and read the right part whcih is the url string[] splits = line.Split(new string[]{"!#!"},StringSplitOptions.RemoveEmptyEntries); //load the url once extracted from the text file loadNewTabWithURL(splits[1]); } catch (Exception exp) { //MessageBox.Show(exp.Message); } } //if the menu item clicked is "Edit" else if (subMenuText == "Edit") { //set the index of the favourites AddToFavourites frmAddToFavourites = new AddToFavourites(); frmAddToFavourites.setmyIndex(favindex); //call the dialog box so the user can edit the favourites frmAddToFavourites.ShowDialog(); //refresh the favourites items so they can get updated reloadFavourites(); } //if the menu item clicked is "Remove" else if (subMenuText == "Remove") { try { //read the entire text file into a string and split each line StreamReader rdr = new StreamReader("favourites.txt"); string allFavourites = rdr.ReadToEnd(); string[] splits = allFavourites.Split(new string[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries); rdr.Close(); //find the line which needs to be removed through favindex and rewrite //the entire string again line by line except for the line that needs to be removed StreamWriter rtr = new StreamWriter("favourites.txt",false); for (int i = 0; i < splits.Length; i++) { if (i != favindex) { rtr.WriteLine(splits[i]); } } rtr.Close(); reloadFavourites(); } catch (Exception exp) { ////MessageBox.Show(exp.Message); } } }