ohbutt69

chamone

Oct 30th, 2011
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace Rich_Text_Editor
  12. {
  13.     public partial class RichTextEditor : Form
  14.     {
  15.         public RichTextEditor()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         string fileName = ""; //string fileName variable, to hold the name of a file used with the open or save dialogs
  21.         bool textChanged = false; //boolean variable to monitor if the text has been changed
  22.         bool fileSaved = true;// boolean variable to monitor if the text has been saved
  23.  
  24.         private void newToolStripMenuItem_Click(object sender, EventArgs e)
  25.         {
  26.             if (fileSaved == false)
  27.             {
  28.  
  29.             }
  30.         }
  31.         private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
  32.         {
  33.  
  34.         }
  35.         private void saveFileToolStripMenuItem_Click(object sender, EventArgs e)//working
  36.         {
  37.             if (fileSaved == false) // begins the save process by checking the state of the fileSaved boolean variable
  38.             {
  39.                 saveFileDialog.Filter = "Rich Text Files (*.rtf)|*.rtf|Plaintext Files (*txt)|*.txt";// sets the filter for the saveFileDialog
  40.                 if (fileName != "")// if the file name is not equal to nothing, it starts to save the file (as opposed to save as)
  41.                 {
  42.                     if (fileName.EndsWith("txt"))// if the file name ends in "txt", the program saves the file as plaintext...
  43.                     {
  44.                         rtbContent.SaveFile(fileName, RichTextBoxStreamType.PlainText);// ...in the right file with the name provided in the fileName variable
  45.                     }
  46.                     else if (fileName.EndsWith("rtf"))// if the file name ends in "txt", the program saves the file as richtext...
  47.                     {
  48.                         rtbContent.SaveFile(fileName, RichTextBoxStreamType.RichText);// ...in the right file with the name provided in the fileName variable
  49.                     }
  50.                 }
  51.                 else// if the file Name is equal to nothing program starts the save as process
  52.                 {
  53.                     if (saveFileDialog.ShowDialog() != DialogResult.Cancel)//if the save file dialog is not cancelled, the save as program can proceed
  54.                     {
  55.                         fileName = saveFileDialog.FileName;//assigns the fileName provided by the save file dialog to the fileName variable
  56.                         string saveFileName = saveFileDialog.FileName;// sets the savefileName to the file name provided by the save file dialog
  57.                         if (saveFileName.EndsWith("txt"))// if the file name ends in "txt", the program saves the file as plaintext...
  58.                         {
  59.                             rtbContent.SaveFile(saveFileName, RichTextBoxStreamType.PlainText);// ...in the right file with the name provided in the fileName variable
  60.                         }
  61.                         else if (saveFileName.EndsWith("rtf")) // if the file name ends in "txt", the program saves the file as plaintext...
  62.                         {
  63.                             rtbContent.SaveFile(saveFileName, RichTextBoxStreamType.RichText);// ...in the right file with the name provided in the fileName variable
  64.                         }
  65.                     }
  66.                     fileName = Path.GetFileName(saveFileDialog.FileName);// gets the name of the file selected in the dialog without the directory
  67.                     Text = "RTF Editor" + ": " + fileName;// sets the title of the form to the default name plus the name of the file open
  68.                 }
  69.             }
  70.         }
  71.         private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)//working
  72.         {
  73.          saveFileDialog.Filter = "Rich Text Files (*.rtf)|*.rtf|Plaintext Files (*txt)|*.txt";// sets the filter for the saveFileDialog
  74.                     if (saveFileDialog.ShowDialog() != DialogResult.Cancel)//if the save file dialog is not cancelled, the save as program can proceed
  75.                     {
  76.                         fileName = saveFileDialog.FileName;//assigns the fileName provided by the save file dialog to the fileName variable
  77.                         string saveFileName = saveFileDialog.FileName;// sets the savefileName to the file name provided by the save file dialog
  78.                         if (saveFileName.EndsWith("txt"))// if the file name ends in "txt", the program saves the file as plaintext...
  79.                         {
  80.                             rtbContent.SaveFile(saveFileName, RichTextBoxStreamType.PlainText);// ...in the right file with the name provided in the fileName variable
  81.                         }
  82.                         else if (saveFileName.EndsWith("rtf")) // if the file name ends in "txt", the program saves the file as plaintext...
  83.                         {
  84.                             rtbContent.SaveFile(saveFileName, RichTextBoxStreamType.RichText);// ...in the right file with the name provided in the fileName variable
  85.                         }
  86.                     }
  87.                     fileName = Path.GetFileName(saveFileDialog.FileName);// gets the name of the file selected in the dialog without the directory
  88.                     Text = "RTF Editor" + ": " + fileName;// sets the title of the form to the default name plus the name of the file open
  89.                 }
  90.         private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  91.         {
  92.  
  93.         }
  94.         private void cutToolStripMenuItem_Click(object sender, EventArgs e)//working
  95.         {
  96.             if (rtbContent.SelectedText != "")//if the selected text in the rich text box is not nothing...
  97.             {
  98.                 rtbContent.Cut();// ...Then cut the selection and pass it to the clipboard
  99.             }
  100.         }
  101.         private void copyToolStripMenuItem_Click(object sender, EventArgs e)//working
  102.         {
  103.             if (rtbContent.SelectedText != "")//if the selected text in the rich text box is not nothing...
  104.             {
  105.                 rtbContent.Copy();// ...Then copy the selection and pass it to the clipboard
  106.             }
  107.         }
  108.         private void pasteToolStripMenuItem_Click(object sender, EventArgs e)//working
  109.         {
  110.             if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)//if there is text data present in the clip board...
  111.             {
  112.                 rtbContent.Paste();// ...paste it into the rich text box
  113.             }
  114.         }
  115.         private void fontToolStripMenuItem_Click(object sender, EventArgs e)//working
  116.         {
  117.             if(fontDialog.ShowDialog()  != DialogResult.Cancel)// if the dialog is not cancelled...
  118.             {
  119.                 rtbContent.Font = fontDialog.Font;// ...replace the font value of the RTB with the font value recovered from the font dialog
  120.             }
  121.         }
  122.         private void colourToolStripMenuItem_Click(object sender, EventArgs e)// working
  123.         {
  124.             if (colorDialog.ShowDialog() != DialogResult.Cancel)// if the dialog is not cancelled...
  125.             {
  126.                 rtbContent.ForeColor = colorDialog.Color;// ...replace the Forecolor value of the RTB with the color value recovered from the color dialog
  127.             }
  128.         }
  129.         private void findTextToolStripMenuItem_Click(object sender, EventArgs e)
  130.         {
  131.  
  132.         }
  133.         private void aboutMeToolStripMenuItem_Click(object sender, EventArgs e)//working
  134.         {
  135.             MessageBox.Show("10053670", "About Me", MessageBoxButtons.OK, MessageBoxIcon.Information);//call MessageBox function, set text to "10053670", the title to "About Me" and give the box an ok button and an information symbol
  136.         }
  137.         private void tsbNew_Click(object sender, EventArgs e)
  138.         {
  139.  
  140.         }
  141.         private void tsbOpen_Click(object sender, EventArgs e)
  142.         {
  143.  
  144.         }
  145.         private void tsbSave_Click(object sender, EventArgs e) //working
  146.         {
  147.             if (fileSaved == false) // begins the save process by checking the state of the fileSaved boolean variable
  148.             {
  149.                 saveFileDialog.Filter = "Rich Text Files (*.rtf)|*.rtf|Plaintext Files (*txt)|*.txt";// sets the filter for the saveFileDialog
  150.                 if (fileName != "")// if the file name is not equal to nothing, it starts to save the file (as opposed to save as)
  151.                 {
  152.                     if (fileName.EndsWith("txt"))// if the file name ends in "txt", the program saves the file as plaintext...
  153.                     {
  154.                         rtbContent.SaveFile(fileName, RichTextBoxStreamType.PlainText);// ...in the right file with the name provided in the fileName variable
  155.                     }
  156.                     else if (fileName.EndsWith("rtf"))// if the file name ends in "txt", the program saves the file as richtext...
  157.                     {
  158.                         rtbContent.SaveFile(fileName, RichTextBoxStreamType.RichText);// ...in the right file with the name provided in the fileName variable
  159.                     }
  160.                 }
  161.                 else// if the file Name is equal to nothing program starts the save as process
  162.                 {
  163.                     if (saveFileDialog.ShowDialog() != DialogResult.Cancel)//if the save file dialog is not cancelled, the save as program can proceed
  164.                     {
  165.                         fileName = saveFileDialog.FileName;//assigns the fileName provided by the save file dialog to the fileName variable
  166.                         string saveFileName = saveFileDialog.FileName;// sets the savefileName to the file name provided by the save file dialog
  167.                         if (saveFileName.EndsWith("txt"))// if the file name ends in "txt", the program saves the file as plaintext...
  168.                         {
  169.                             rtbContent.SaveFile(saveFileName, RichTextBoxStreamType.PlainText);// ...in the right file with the name provided in the fileName variable
  170.                         }
  171.                         else if (saveFileName.EndsWith("rtf")) // if the file name ends in "txt", the program saves the file as plaintext...
  172.                         {
  173.                             rtbContent.SaveFile(saveFileName, RichTextBoxStreamType.RichText);// ...in the right file with the name provided in the fileName variable
  174.                         }
  175.                     }
  176.                     fileName = Path.GetFileName(saveFileDialog.FileName);// gets the name of the file selected in the dialog without the directory
  177.                     Text = "RTF Editor" + ": " + fileName;// sets the title of the form to the default name plus the name of the file open
  178.                 }
  179.             }
  180.         }
  181.         private void tsbCut_Click(object sender, EventArgs e) //working
  182.         {
  183.             if (rtbContent.SelectedText != "")//if the selected text in the rich text box is not nothing...
  184.             {
  185.                 rtbContent.Cut();// ...Then cut the selection and pass it to the clipboard
  186.             }
  187.         }
  188.         private void tsbCopy_Click(object sender, EventArgs e)//working
  189.         {
  190.             if (rtbContent.SelectedText != "")//if the selected text in the rich text box is not nothing...
  191.             {
  192.                 rtbContent.Copy();// ...Then copy the selection and pass it to the clipboard
  193.             }
  194.         }  
  195.         private void tsbPaste_Click(object sender, EventArgs e)//working
  196.         {
  197.             if(Clipboard.GetDataObject() .GetDataPresent(DataFormats.Text) == true)//if there is text data present in the clip board...
  198.             {
  199.                 rtbContent.Paste();// ...paste it into the rich text box
  200.             }
  201.         }
  202.         private void tsbAbout_Click(object sender, EventArgs e)//working
  203.         {
  204.             MessageBox.Show("10053670", "About Me", MessageBoxButtons.OK, MessageBoxIcon.Information);//call MessageBox function, set text to "10053670", the title to "About Me" and give the box an ok button and an information symbol
  205.         }
  206.         private void rtbContent_TextChanged(object sender, EventArgs e)//working
  207.         {
  208.             textChanged = true;// set the text changed variable to true
  209.             fileSaved = false;// set the file saved variable to false, this indicates that the text in the RTB has been changed and saved when necessary
  210.         }
  211.         private void RichTextEditor_FormClosing(object sender, FormClosingEventArgs e)
  212.         {
  213.             if (fileSaved == false)
  214.             {
  215.                 MessageBox.Show("ohbutt");
  216.             }
  217.         }
  218.     }
  219. }
  220.  
  221.  
Advertisement
Add Comment
Please, Sign In to add comment