internal DocumentForm() { InitializeComponents(); unsavedChanges = new UnsavedChanges(this, Save); fileName = string.Empty; FormClosing += (s, e) => { if (unsavedChanges.WereNotHandled()) { e.Cancel = true; } }; richTextBox.TextChanged += (s, e) => { var indicator = " *"; if ((fileName != string.Empty) && !Text.EndsWith(fileName + indicator)) { Text += indicator; } unsavedChanges.HaveOccurred(); }; richTextBox.KeyPress += (s, e) => { if ((Keys)e.KeyChar == Keys.Tab) { InsertSpacesForTab(); e.Handled = true; } if ((Keys)e.KeyChar == Keys.Enter) { IndentNewLine(); e.Handled = true; } }; }