Zebra0.com

visual-basic richtext

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.

  1. Continue with the MyNotes Application.
  2. Find the New item on the menu and double click to open the code view.
  3. Write the code as shown below:
  4.     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
  5. Click Save All SaveAllat this point and run the program.
  6. 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.

NEXT: Add a ToolBar