private void miSave_Click(object sender, EventArgs e) { if (txt != null) { txt = new Text_Value(txt.FileName); txt.Text[0] = rtb_Text.Text; txt.Save(); rtb_Text.Text = txt.Text[0]; this.Text = txt.FileName + " - Блокнот"; } else { SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "Новый текст"; // Default file name sfd.DefaultExt = ".txt"; // Default file extension sfd.Filter = "Text documents (.txt)|*.txt"; if (sfd.ShowDialog() == DialogResult.OK) { txt = new Text_Value(sfd.FileName); txt.Text[0] = rtb_Text.Text; txt.Save(); rtb_Text.Text = txt.Text[0]; this.Text = txt.FileName + " - Блокнот"; } ; } }
private void miNew_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "Новый текст"; // Default file name sfd.DefaultExt = ".txt"; // Default file extension sfd.Filter = "Text documents (.txt)|*.txt"; if (sfd.ShowDialog() == DialogResult.OK) { txt = new Text_Value(sfd.FileName, new string[1]); txt.Save(); rtb_Text.Text = ""; this.Text = txt.FileName + " - Блокнот"; } ; }
protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); if (e.CloseReason == CloseReason.WindowsShutDown) { return; } // Confirm user wants to close switch (MessageBox.Show(this, "Вы хотите сохранить изменения?", "Сохранить изменения?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { case DialogResult.Yes: if (txt != null) { txt = new Text_Value(txt.FileName); txt.Text[0] = rtb_Text.Text; txt.Save(); rtb_Text.Text = txt.Text[0]; this.Text = txt.FileName + " - Блокнот"; } else { SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "Новый текст"; // Default file name sfd.DefaultExt = ".txt"; // Default file extension sfd.Filter = "Text documents (.txt)|*.txt"; if (sfd.ShowDialog() == DialogResult.OK) { txt = new Text_Value(sfd.FileName); txt.Text[0] = rtb_Text.Text; txt.Save(); rtb_Text.Text = txt.Text[0]; } ; } break; default: break; } }