GetRichTextBox() public method

public GetRichTextBox ( ) : RichTextBox
return RichTextBox
コード例 #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            Form2 f2 = this.ActiveMdiChild as Form2;

            if (f2 == null)
            {
                return;
            }
            RichTextBox box    = f2.GetRichTextBox();
            int         line   = box.GetLineFromCharIndex(box.SelectionStart);
            int         column = box.SelectionStart - box.GetFirstCharIndexFromLine(line);

            this.statusStrip1.Items[0].Text = string.Format("{0}, {1}", line, column);
        }
コード例 #2
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 f2 = (Form2)this.ActiveMdiChild;

            if (f2 == null)
            {
                return;
            }
            if (!f2.TabText.EndsWith("*"))
            {
                return;
            }
            File.WriteAllText((string)f2.Tag, f2.GetRichTextBox().Text, Encoding.Default);
            f2.TabText = f2.TabText.Substring(0, f2.TabText.Length - 1);
        }
コード例 #3
0
        private void OpenFile(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }
            if (GetForm2ByPath(path) != null)
            {
                return;
            }

            Form2 child = new Form2();

            child.MdiParent = this;
            child.TabText   = Path.GetFileName(path);
            child.Tag       = path;

            RichTextBox box = child.GetRichTextBox();

            box.AllowDrop  = true;
            box.DragEnter += this.dockPanel1_DragEnter;
            box.DragDrop  += this.dockPanel1_DragDrop;
            box.Text       = File.ReadAllText(path, Encoding.Default).Replace("\r\n", "\n");

            {
                ContextMenuStrip menu = new ContextMenuStrip();
                menu.Items.Add("Cut").Click   += (o, e) => { box.Cut(); };
                menu.Items.Add("Copy").Click  += (o, e) => { box.Copy(); };
                menu.Items.Add("Paste").Click += (o, e) => { box.Paste(); };
                box.ContextMenuStrip           = menu;
            }

            box.KeyUp       += this.Form1_KeyUp;
            box.TextChanged += (o, e) => { if (child.TabText.EndsWith("*"))
                                           {
                                               return;
                                           }
                                           child.TabText = child.TabText + "*"; };


            {
                ContextMenuStrip menu = new ContextMenuStrip();
                menu.Items.Add("Close").Click += this.closeToolStripMenuItem_Click;
                menu.Items.Add("Close All But This").Click += (o, e) =>
                {
                    this.ActivateMdiChild(child);
                    foreach (var i in this.MdiChildren)
                    {
                        if (i != child)
                        {
                            i.Close();
                            i.MdiParent = null;
                        }
                    }
                };
                child.TabPageContextMenuStrip = menu;
            }

            child.DockAreas = WeifenLuo.WinFormsUI.Docking.DockAreas.Document;
            child.Show(dockPanel1);

            m_treeViewList.AddFilePath(path);
            child.Disposed += (o, e) => { if (m_treeViewList != null && !m_treeViewList.IsDisposed)
                                          {
                                              m_treeViewList.RemoveFilePath(child.Tag.ToString());
                                          }
            };
        }
コード例 #4
0
        public Form1()
        {
            InitializeComponent();

            m_propertyGrid = new Form3();
            m_propertyGrid.Show(dockPanel1);
            m_propertyGrid.DockTo(dockPanel1, DockStyle.Right);

            this.MdiChildActivate += (o, e) =>
            {
                if (this.ActiveMdiChild == null)
                {
                    return;
                }

                PropertyGrid grid = m_propertyGrid.GetPropertyGrid();
                grid.SelectedObject = new FileInfo((this.ActiveMdiChild as Form2).Tag.ToString());

                m_treeViewList.SelectFilePath((this.ActiveMdiChild as Form2).Tag.ToString());
            };

            m_treeViewList = new Form4();
            m_treeViewList.Show(dockPanel1);
            m_treeViewList.DockTo(dockPanel1, DockStyle.Left);

            m_treeViewList.GetFileSysTreeView().NodeMouseDoubleClick += (o, e) =>
            {
                string path = m_treeViewList.GetPathByNode(e.Node);
                Form2  form = GetForm2ByPath(path);
                if (form == null)
                {
                    return;
                }
                this.ActivateMdiChild(form);
            };

            m_treeViewList.FileChanged += s =>
            {
                Form2 f2 = GetForm2ByPath(s);
                if (f2 == null)
                {
                    return;
                }
                if (f2.GetRichTextBox().Text == File.ReadAllText(s, Encoding.Default).Replace("\r\n", "\n"))
                {
                    return;
                }

                if (MessageBox.Show(s + "被从外部改变,要重新加载吗?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    ActivateMdiChild(f2);
                    this.closeToolStripMenuItem_Click(null, null);
                    OpenFile(s);
                }
            };
            m_treeViewList.FileDeleted += s =>
            {
                Form2 f2 = GetForm2ByPath(s);
                if (f2 == null)
                {
                    return;
                }
                if (MessageBox.Show(s + "被从外部删除,要关闭文件吗?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    ActivateMdiChild(f2);
                    this.closeToolStripMenuItem_Click(null, null);
                }
            };
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: GHScan/DailyProjects
        private void OpenFile(string path)
        {
            if (!File.Exists(path)) return;
            if (GetForm2ByPath(path) != null) return;

            Form2 child = new Form2();
            child.MdiParent = this;
            child.TabText = Path.GetFileName(path);
            child.Tag = path;

            RichTextBox box = child.GetRichTextBox();
            box.AllowDrop = true;
            box.DragEnter += this.dockPanel1_DragEnter;
            box.DragDrop += this.dockPanel1_DragDrop;
            box.Text = File.ReadAllText(path, Encoding.Default).Replace("\r\n", "\n");

            {
                ContextMenuStrip menu = new ContextMenuStrip();
                menu.Items.Add("Cut").Click += (o, e) => { box.Cut(); };
                menu.Items.Add("Copy").Click += (o, e) => { box.Copy(); };
                menu.Items.Add("Paste").Click += (o, e) => { box.Paste(); };
                box.ContextMenuStrip = menu;
            }

            box.KeyUp += this.Form1_KeyUp;
            box.TextChanged += (o, e) => { if (child.TabText.EndsWith("*")) return; child.TabText = child.TabText + "*"; };

            {
                ContextMenuStrip menu = new ContextMenuStrip();
                menu.Items.Add("Close").Click += this.closeToolStripMenuItem_Click;
                menu.Items.Add("Close All But This").Click += (o, e) =>
                    {
                        this.ActivateMdiChild(child);
                        foreach (var i in this.MdiChildren)
                        {
                            if (i != child)
                            {
                                i.Close();
                                i.MdiParent = null;
                            }
                        }
                    };
                child.TabPageContextMenuStrip = menu;
            }

            child.DockAreas = WeifenLuo.WinFormsUI.Docking.DockAreas.Document;
            child.Show(dockPanel1);

            m_treeViewList.AddFilePath(path);
            child.Disposed += (o, e) => { if(m_treeViewList != null && !m_treeViewList.IsDisposed) m_treeViewList.RemoveFilePath(child.Tag.ToString()); };
        }