private void SwitchDocument(Document nextDocument) { Scintilla newText = new Scintilla(); var prevDocument = newText.Document; newText.AddRefDocument(prevDocument); newText.Dock = DockStyle.Fill; newText.Document = nextDocument; newText.ReleaseDocument(nextDocument); tabControl1.SelectedTab.Tag = prevDocument; tabControl1.SelectedTab.Controls.Add(newText); textarea.AddRefDocument(prevDocument); tabControl1.MouseDown += TabControl1_MouseDown; }
public void NewDocument(bool addNewPage) { if (addNewPage) { TabPage tabPage = new TabPage(string.Format("new {0}", tabCount)); Scintilla newTab = new Scintilla(); tabControl1.TabPages.Add(tabPage); tabPage.Controls.Add(newTab); newTab.Dock = DockStyle.Fill; init(newTab); ////line numbers //newTab.Margins[0].Width = 16; //// Use margin 2 for fold markers //newTab.Margins[2].Type = MarginType.Symbol; //newTab.Margins[2].Mask = Marker.MaskFolders; //newTab.Margins[2].Sensitive = true; //newTab.Margins[2].Width = 20; var document = newTab.Document; newTab.AddRefDocument(document); newTab.Document = Document.Empty; tabPage.Tag = document; tabControl1.SelectedTab = tabPage; tabCount++; } else { var document = textarea.Document; textarea.AddRefDocument(document); textarea.Document = Document.Empty; tabControl1.SelectedTab.Tag = document; tabCount++; } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { using (OpenFileDialog of = new OpenFileDialog() { Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*", Multiselect = false, ValidateNames = true, RestoreDirectory = true, Title = "Browse Text Files", DefaultExt = "txt" }) { if (of.ShowDialog() == DialogResult.OK) { using (StreamReader reader = new StreamReader(of.FileName)) { try { TabPage tabPage = new TabPage(string.Format("new {0}", tabCount)); Scintilla newTab = new Scintilla(); tabControl1.TabPages.Add(tabPage); tabPage.Controls.Add(newTab); newTab.Dock = DockStyle.Fill; init(newTab); ////line numbers //newTab.Margins[0].Width = 16; //// Use margin 2 for fold markers //newTab.Margins[2].Type = MarginType.Symbol; //newTab.Margins[2].Mask = Marker.MaskFolders; //newTab.Margins[2].Sensitive = true; //newTab.Margins[2].Width = 20; // path = of.FileName; // string name1 = System.IO.Path.GetFileName(of.FileName); //// tabControl1.SelectedTab.Text = name1; var document = newTab.Document; newTab.AddRefDocument(document); newTab.Document = Document.Empty; tabPage.Tag = document; tabControl1.SelectedTab = tabPage; tabCount++; //NewDocument(true); path = of.FileName; Task <string> str = reader.ReadToEndAsync(); newTab.Text = str.Result; string name = System.IO.Path.GetFileName(of.FileName); tabControl1.SelectedTab.Text = name; tabname = System.IO.Path.GetFileName(of.FileName); tabControl1.SelectedTab.Text = tabname; } catch (Exception ex) { MessageBox.Show(ex.Message, "Message: ", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }