We have created an Application called MyNotes with a rich text box, a menu with standard items, and a toolstrip. The rich text box fills the form.
Next we will write the code to implement New. The is a corresponding button on the toolbar and we will write one sub to handle both events.
- Continue with the MyNotes Application.
- Find the New item on the menu and double click to open the code view.
- Write the code as shown below:
Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles NewToolStripMenuItem.Click, NewToolStripButton.Click
RichTextBox1.Text = "" 'Erases the text in the RichTextBox
Me.Text = "Untitled"
OpenFileDialog1.FileName = "" 'If the user clicks save we want to show the SaveFileDialog
End Sub
- Click Save All at this point and run the program.
- Open one of the rtf files you created, modify, then click New. It just erases your text without asking to save.
What is missing at this point is the implementation checking that the file has been saved when we close the program. This is similar to what we did with the ToDo list.