Example #1
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 #2
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 #3
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)
                {
                }
            }
        }
Example #4
0
        private void newTabPage()
        {
            CustomRichTextBox richTextBox = new CustomRichTextBox(new Model.Content());
            TabPage           tabPage     = new TabPage("new File");

            this.tcMain.TabPages.Insert(this.tcMain.TabPages.Count - 1, tabPage);
            tabPage.Controls.Add(richTextBox);
            richTextBox.Dock         = DockStyle.Fill;
            richTextBox.TextChanged += this.rtbTextChanged;
            this.tcMain.SelectedTab  = tabPage;

            this.customTextRichBoxes.Add(richTextBox);
            richTextBox.Select();
        }
Example #5
0
        private void newChildForm()
        {
            CustomRichTextBox richTextBox = new CustomRichTextBox(new Model.Content());

            richTextBox.Dock         = DockStyle.Fill;
            richTextBox.TextChanged += this.rtbTextChanged;
            Form form = new Form();

            form.MdiParent = this;
            form.Controls.Add(richTextBox);
            form.Show();

            this.customTextRichBoxes.Add(richTextBox);
            richTextBox.Select();
        }
Example #6
0
        private void searchInRichTextBox(CustomRichTextBox richTextBox)
        {
            richTextBox.TextChanged -= ((FrmMain)this.Owner).rtbTextChanged;
            string text = richTextBox.Text;

            richTextBox.Clear();

            richTextBox.Text = text;
            startIndex       = richTextBox.Text.IndexOf(cmbFind.Text, startIndex + 1);
            if (startIndex != -1)
            {
                richTextBox.Select(startIndex, cmbFind.Text.Length);
                richTextBox.SelectionColor     = System.Drawing.Color.White;
                richTextBox.SelectionBackColor = System.Drawing.Color.Blue;
                richTextBox.TextChanged       += ((FrmMain)this.Owner).rtbTextChanged;
            }
        }
Example #7
0
        public FrmMain()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("es-ES");
            // Sets the UI culture to French (France)
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-ES");
            InitializeComponent();

            customTextRichBoxes = new List <CustomRichTextBox>();


            CustomRichTextBox richTextBox = new CustomRichTextBox(new Model.Content());

            richTextBox.Dock = DockStyle.Fill;

            tp1.Controls.Add(richTextBox);
            richTextBox.TextChanged += this.rtbTextChanged;
            this.tcMain.SelectedTab  = tp1;
            this.customTextRichBoxes.Add(richTextBox);
            richTextBox.Select();
        }