Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace NoteBook1
- {
- public partial class Form1 : Form
- {
- private bool isFilePath;
- private bool isFileSave;
- private bool isDirty;
- public Form1()
- {
- InitializeComponent();
- }
- private void MenuNewFileClick(object sender, EventArgs e)
- {
- if ((isFilePath && isFileSave)|| (richTextBox1.Text == string.Empty))
- {
- richTextBox1.Text = string.Empty;
- }
- else
- {
- NewFileMessage();
- }
- }
- private void NewFileMessage()
- {
- SaveFileDialog saveAs = new SaveFileDialog();
- DialogResult dialogResult = MessageBox.Show("Do you want to save changes to file?", "My noteBook", MessageBoxButtons.YesNoCancel);
- if (DialogResult.Yes == dialogResult)
- {
- isFilePath = true;
- isFileSave = true;
- saveAs.ShowDialog();
- SaverToFile(saveAs);
- richTextBox1.Text = string.Empty;
- }
- else if (DialogResult.No == dialogResult)
- {
- richTextBox1.Text = string.Empty;
- }
- else { }
- }
- private void SaverToFile(SaveFileDialog filePass)
- {
- if (isFilePath)
- {
- using (StreamWriter saveToFile = new StreamWriter(filePass.FileName))
- {
- saveToFile.WriteLine(richTextBox1.Text);
- }
- }
- else
- {
- NewFileMessage();
- }
- }
- private void richTextBox1_TextChanged(object sender, EventArgs e)
- {
- isDirty = true;
- }
- private void MenuOpenFileClick(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- DialogResult dialogResult = openFileDialog.ShowDialog();
- if (DialogResult.Yes == dialogResult)
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement