Example #1
0
        public void load()
        {
            //Set dialog rules.
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            ofd.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            ofd.RestoreDirectory = true;
            Stream stream;

            //Check dialog response and whether file is empty or not. If not, read and put invoke everything on rich text box.
            //Set current file name
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if ((stream = ofd.OpenFile()) != null)
                {
                    string[] fileNameSplit = ofd.FileName.Split('\\');
                    f.setCurrentFile(fileNameSplit[fileNameSplit.Length - 1]);
                    f.getCommandsRichTextBox().Clear();
                    TextReader tr = new StreamReader(stream);
                    f.getCommandsRichTextBox().Text = tr.ReadToEnd();
                    tr.Close();
                    stream.Close();
                }
            }
        }
Example #2
0
        public void save()
        {
            //Write the contents of rich text box into memory stream
            f.getCommandsRichTextBox().SaveFile(ms, RichTextBoxStreamType.PlainText);
            ms.WriteByte(13);


            //Create dialog to save file and set the rules of the dialog
            sfd = new SaveFileDialog();
            sfd.CreatePrompt    = true;
            sfd.OverwritePrompt = true;

            if (!f.getCurrentFile().Equals(""))
            {
                sfd.FileName = f.getCurrentFile();
            }
            else
            {
                sfd.FileName = "My Program";
            }
            sfd.DefaultExt       = "txt";
            sfd.Filter           = "Text (*.txt)|*.txt|All files (*.*)|*.*";
            sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            DialogResult result = sfd.ShowDialog();
            Stream       stream;

            if (result == DialogResult.OK)
            {
                stream      = sfd.OpenFile();
                ms.Position = 0;
                ms.WriteTo(stream);
                stream.Close();
            }
        }
Example #3
0
 public void clearTextFunction()
 {
     f.getCommandsRichTextBox().Clear();
 }