Zebra0.com

csharp richtext

Continue with the Notes Application.

Next we will write the code to implement New. The is a corresponding button on the toolbar and we will write the code to handle both events.

private void NewDocument()
{
   // Delete everything from richtext box
   // Remind to save.
   Boolean cancel = AskToSave();
   // If user did not select cancel, continue.
   if (!cancel)
   {
      // Delete the contents of the rich text box.
      richTextBox1.Text = "";
      // Set the filename to untitled.
      currentFileName = "Untitled";
      // No changes so far.
      changed = false;
      // Show untitled in status bar.
      toolStripStatusFilename.Text = currentFileName;
   }
}

// Click both the new button and new menu item and write the code:
private void newToolStripButton_Click(object sender, EventArgs e)
{
   // Delete everything from richtext box
   NewDocument();
}

private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
   // Delete everything from richtext box
   NewDocument();
}

Click Save All at this point and run the program.

End of lesson, Next lesson: That is the last C# lesson in this course.