Advertisement
aslen

Untitled

May 10th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.39 KB | None | 0 0
  1.                
  2.                
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using System.IO;
  13.  
  14. namespace NoteBook1
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         private bool isFilePath;
  19.         private bool isFileSave;
  20.         private bool isDirty;
  21.  
  22.         public Form1()
  23.         {
  24.             InitializeComponent();
  25.         }
  26.  
  27.         private void MenuNewFileClick(object sender, EventArgs e)
  28.         {
  29.             if ((isFilePath && isFileSave)|| (richTextBox1.Text == string.Empty))
  30.             {
  31.                 richTextBox1.Text = string.Empty;
  32.             }
  33.             else
  34.             {
  35.                 NewFileMessage();
  36.             }
  37.         }
  38.         private void NewFileMessage()
  39.         {
  40.             SaveFileDialog saveAs = new SaveFileDialog();
  41.             DialogResult dialogResult = MessageBox.Show("Do you want to save changes to file?", "My noteBook", MessageBoxButtons.YesNoCancel);
  42.             if (DialogResult.Yes == dialogResult)
  43.             {
  44.                 isFilePath = true;
  45.                 isFileSave = true;
  46.                 saveAs.ShowDialog();
  47.                 SaverToFile(saveAs);
  48.                 richTextBox1.Text = string.Empty;
  49.             }
  50.             else if (DialogResult.No == dialogResult)
  51.             {
  52.                 richTextBox1.Text = string.Empty;
  53.             }
  54.             else { }
  55.         }
  56.         private void SaverToFile(SaveFileDialog filePass)
  57.         {
  58.             if (isFilePath)
  59.             {
  60.                 using (StreamWriter saveToFile = new StreamWriter(filePass.FileName))
  61.                 {
  62.                     saveToFile.WriteLine(richTextBox1.Text);
  63.                 }
  64.             }
  65.             else
  66.             {
  67.                 NewFileMessage();
  68.             }
  69.         }
  70.  
  71.         private void richTextBox1_TextChanged(object sender, EventArgs e)
  72.         {
  73.             isDirty = true;
  74.         }
  75.  
  76.         private void MenuOpenFileClick(object sender, EventArgs e)
  77.         {
  78.             OpenFileDialog openFileDialog = new OpenFileDialog();
  79.             DialogResult dialogResult = openFileDialog.ShowDialog();
  80.             if (DialogResult.Yes == dialogResult)
  81.             {
  82.                
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement