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 SaveAs. There is not a corresponding button for the menu item..
- Continue with the MyNotes Application.
- Find the SaveAs item on the menu and double click to open the code view.
- Write the code as shown below:
Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles SaveAsToolStripMenuItem.Click
SaveFileDialog1.FileName = OpenFileDialog1.FileName 'Set opened file to default
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> "" Then 'They did not cancel
RichTextBox1.SaveFile(SaveFileDialog1.FileName)
Me.Text = SaveFileDialog1.FileName
End If
End Sub
- Click Save All
at this point and run the program.
- Open one of the rtf files you created, then try Save, SaveAs and Open.
Next we will write the code to implement New.