Example #1
0
        void Open()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "TXT (*.txt)|*.txt|RTF (*.rtf)|*.rtf";

            if (openFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            else
            {
                SaveForm     saveForm     = new SaveForm();
                DialogResult dialogResult = saveForm.ShowDialog();
                if (dialogResult == DialogResult.Yes)
                {
                    if (currentFile == "")
                    {
                        StreamWriter   SW;
                        SaveFileDialog SFD = new SaveFileDialog();
                        SFD.FileName = "";
                        SFD.Filter   = "TXT (*.txt)|*.txt|RTF (*.rtf)|*.rtf";

                        if (SFD.ShowDialog() == DialogResult.OK)
                        {
                            SW = new StreamWriter(SFD.FileName);
                            SW.Write(richTextBoxIn.Text.ToString());
                            SW.Close();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        Save();
                    }
                }
                string file = openFileDialog.FileName;
                string txt  = File.ReadAllText(file);
                richTextBoxIn.Text = txt;
                currentFile        = file;
            }
        }
Example #2
0
        void Create()
        {
            SaveForm     saveForm     = new SaveForm();
            DialogResult dialogResult = saveForm.ShowDialog();

            if (dialogResult == DialogResult.Yes)
            {
                if (currentFile == "")
                {
                    StreamWriter   SW;
                    SaveFileDialog SFD = new SaveFileDialog();
                    SFD.FileName = "";
                    SFD.Filter   = "TXT (*.txt)|*.txt|RTF (*.rtf)|*.rtf";

                    if (SFD.ShowDialog() == DialogResult.OK)
                    {
                        SW = new StreamWriter(SFD.FileName);
                        SW.Write(richTextBoxIn.Text.ToString());
                        SW.Close();
                        richTextBoxIn.Clear();
                    }
                    currentFile = "";
                }
                else
                {
                    Save();
                    currentFile = "";
                    richTextBoxIn.Clear();
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                richTextBoxIn.Clear();
                currentFile = "";
            }
            else
            {
                return;
            }
        }