Example #1
0
        private void myOwnForm_Closing(object sender, FormClosingEventArgs e)
        {
            int i = 0;

            if (this.tsmTabbed.Checked)
            {
                foreach (CustomRichTextBox richTextBox in this.customTextRichBoxes)
                {
                    Model.Content content = richTextBox.Content;
                    tcMain.SelectedTab = tcMain.TabPages[i];
                    i++;
                    if (content.DirtyBit)
                    {
                        switch (this.showSaveQuestion(content.FileName))
                        {
                        case DialogResult.Yes:

                            this.tsmiSave_Click(sender, e);

                            break;

                        case DialogResult.Cancel:
                            e.Cancel = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                foreach (CustomRichTextBox richTextBox in this.customTextRichBoxes)
                {
                    Model.Content content = richTextBox.Content;
                    this.MdiChildren[i].Focus();



                    i++;
                    if (content.DirtyBit)
                    {
                        switch (this.showSaveQuestion(content.FileName))
                        {
                        case DialogResult.Yes:

                            this.tsmiSave_Click(sender, e);

                            break;

                        case DialogResult.Cancel:
                            e.Cancel = true;
                            break;
                        }
                    }
                }
            }
        }
Example #2
0
 private void tsmiSaveAs_Click(object sender, EventArgs e)
 {
     if (this.tsmTabbed.Checked)
     {
         SaveFileDialog saveFileDialog = new SaveFileDialog();
         if (saveFileDialog.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 TabPage selectedTab = this.tcMain.SelectedTab;
                 foreach (Control control in selectedTab.Controls)
                 {
                     try
                     {
                         CustomRichTextBox richTextBox = (CustomRichTextBox)control;
                         System.IO.File.WriteAllText(saveFileDialog.FileName, richTextBox.Text);
                         Model.Content content = richTextBox.Content;
                         content.FileName = saveFileDialog.FileName;
                         content.offDirtyBit();
                         this.Text = "MyOwnTextEditor - " + content.FileName;
                         this.tcMain.SelectedTab.Text = content.FileName;
                         richTextBox.Select();
                     }
                     catch (InvalidCastException ex) { }
                 }
             }
             catch (Exception exception)
             {
                 MessageBox.Show("There was an error writing the file");
             }
         }
     }
     else
     {
         SaveFileDialog saveFileDialog = new SaveFileDialog();
         if (saveFileDialog.ShowDialog() == DialogResult.OK)
         {
             try {
                 Form form = this.ActiveMdiChild;
                 CustomRichTextBox richTextBox = (CustomRichTextBox)form.Controls[0];
                 System.IO.File.WriteAllText(saveFileDialog.FileName, richTextBox.Text);
                 Model.Content content = richTextBox.Content;
                 content.FileName = saveFileDialog.FileName;
                 content.offDirtyBit();
                 this.Text = "MyOwnTextEditor - " + content.FileName;
                 form.Text = content.FileName;
                 richTextBox.Select();
             }
             catch (NullReferenceException ex) {
             }
         }
     }
 }
Example #3
0
        private void open()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (this.tsmTabbed.Checked)
                    {
                        TabPage selectedTab = this.tcMain.SelectedTab;
                        foreach (Control control in selectedTab.Controls)
                        {
                            try
                            {
                                CustomRichTextBox richTextBox = (CustomRichTextBox)control;
                                richTextBox.Text = System.IO.File.ReadAllText(openFileDialog.FileName);

                                Model.Content content = richTextBox.Content;
                                content.FileName = openFileDialog.FileName;
                                content.offDirtyBit();

                                this.Text        = "MyOwnTextEditor - " + content.FileName;
                                selectedTab.Text = content.FileName;
                                richTextBox.Select();
                            }
                            catch (InvalidCastException e) { }
                        }
                    }
                    else
                    {
                        Form form = this.MdiChildren.Last();
                        try
                        {
                            CustomRichTextBox richTextBox = (CustomRichTextBox)form.Controls[0];

                            richTextBox.Text = System.IO.File.ReadAllText(openFileDialog.FileName);
                            Model.Content content = richTextBox.Content;
                            content.FileName = openFileDialog.FileName;
                            content.offDirtyBit();
                            form.Text = content.FileName;
                            richTextBox.Select();
                        }
                        catch (InvalidCastException ex) { }
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show("There was an error reading the file");
                }
            }
        }
Example #4
0
        private void tsmiSave_Click(object sender, EventArgs e)
        {
            if (this.tsmTabbed.Checked)
            {
                if (customTextRichBoxes[tcMain.SelectedIndex].Content.FileName == String.Empty)
                {
                    this.tsmiSaveAs_Click(sender, e);
                }
                else
                {
                    TabPage selectedTab = this.tcMain.SelectedTab;
                    foreach (Control control in selectedTab.Controls)
                    {
                        try
                        {
                            CustomRichTextBox richTextBox = (CustomRichTextBox)control;
                            System.IO.File.WriteAllText(this.customTextRichBoxes[this.tcMain.SelectedIndex].Content.FileName, richTextBox.Text);
                            Model.Content content = this.customTextRichBoxes[this.tcMain.SelectedIndex].Content;
                            content.offDirtyBit();
                            selectedTab.Text = content.FileName;
                            richTextBox.Select();
                        }
                        catch (InvalidCastException ex) { }
                    }
                }
            }
            else
            {
                try
                {
                    Form form = this.ActiveMdiChild;


                    CustomRichTextBox richTextBox = (CustomRichTextBox)form.Controls[0];
                    if (richTextBox.Content.FileName == String.Empty)
                    {
                        this.tsmiSaveAs_Click(sender, e);
                    }
                    else
                    {
                        System.IO.File.WriteAllText(richTextBox.Content.FileName, richTextBox.Text);
                        Model.Content content = richTextBox.Content;
                        content.offDirtyBit();
                        form.Text = content.FileName;
                        richTextBox.Select();
                    }
                }
                catch (NullReferenceException ex)
                {
                }
            }
        }
 public CustomRichTextBox(Model.Content content)
 {
     this.Content = content;
 }