public static void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Console.WriteLine("{0}", e.Link.LinkData); string[] path = e.Link.LinkData.ToString().Split(';'); foreach (TabPage tab in staticTabcontrol.TabPages) { if (tab.Text.Equals(Path.GetFileName(path[0]))) { currentTab = tab; staticTabcontrol.SelectedTab = tab; focusedRichTextBox = tab.Controls.OfType<RichTextBoxSynchronizedScroll>().First(); if (int.Parse(path[1]) > focusedRichTextBox.Lines.Count()) return; focusedRichTextBox.SelectionStart = focusedRichTextBox.Find(focusedRichTextBox.Lines[int.Parse(path[1])]); focusedRichTextBox.ScrollToCaret(); int firstcharindex = focusedRichTextBox.GetFirstCharIndexOfCurrentLine(); string currenttext = focusedRichTextBox.Lines[int.Parse(path[1])]; focusedRichTextBox.Select(firstcharindex, currenttext.Length); focusedRichTextBox.SelectionBackColor = Color.YellowGreen; } } }
private void tabControl1_Selected(object sender, TabControlEventArgs e) { listBox2.Items.Clear(); currentTab = e.TabPage; Font fontSize = listBox1.Font; if (e.TabPage.HasChildren) { richTextBox2.Text = ""; currentTab.Controls.Add(richTextBox2); focusedRichTextBox = e.TabPage.Controls.OfType<RichTextBoxSynchronizedScroll>().First(); try { if (focusedRichTextBox.Text != "" && focusedRichTextBox.Lines.Length > 1) { elementGetter(); } } catch (XmlException xe) { listBox1.Items.Add(xe.Message); } focusedRichTextBox.Font = fontSize; HighLight.hLRTF(focusedRichTextBox); focusedRichTextBox.vScroll += scrollSyncTxtBox1_vScroll; focusedRichTextBox.MouseWheel += FocusedRichTextBox_MouseWheel; currentxsd = null; isvalidated = false; lineNumbering(); } }
private void openXMLFile(string xmlPath, Stream xmlStream) { Font font = listBox1.Font; using (StreamReader sr = new StreamReader(xmlPath)) { /*if (xmlStream != null) {*/ RichTextBoxSynchronizedScroll box = new RichTextBoxSynchronizedScroll(); box.Dock = DockStyle.Fill; box.Multiline = true; box.AcceptsTab = true; box.Text = sr.ReadToEnd(); //box.BackColor = Color.Black; XDocument doc = XDocument.Parse(box.Text); TabPage tab = addTab(xmlPath); foreach (var name in doc.Root.DescendantNodes().OfType<XElement>().Select(x => x.Name).Distinct()) { listBox2.Items.Add(name); } tab.Controls.Add(richTextBox2); //........................................................................... tab.Controls.Add(box); tab.Controls.SetChildIndex(box, 0); focusedRichTextBox = box; focusedRichTextBox.Font = font; focusedRichTextBox.vScroll += scrollSyncTxtBox1_vScroll; focusedRichTextBox.MouseWheel += FocusedRichTextBox_MouseWheel; HighLight.hLRTF(focusedRichTextBox); listBox1.Items.Add("XML file loaded"); lineNumbering(); //} } }
private void makeNewTab(int lastIndex) { string xnode = "<?xml version=\"1.0\" encoding=\"UTF - 16\"?>"; TabPage myTabPage = new TabPage("Untitled"); RichTextBoxSynchronizedScroll box = new RichTextBoxSynchronizedScroll(); box.Dock = DockStyle.Fill; box.Multiline = true; box.AcceptsTab = true; myTabPage.Controls.Add(box); myTabPage.Controls.Add(richTextBox2); myTabPage.Controls.SetChildIndex(box, 0); box.Text = xnode; tabControl1.TabPages.Insert(lastIndex, myTabPage); this.tabControl1.SelectedIndex = lastIndex; focusedRichTextBox = box; focusedRichTextBox.vScroll += scrollSyncTxtBox1_vScroll; focusedRichTextBox.MouseWheel += FocusedRichTextBox_MouseWheel; listBox2.Items.Add("szavak"); listBox2.Items.Add("asd"); listBox2.Items.Add("random"); listBox2.Items.Add("lol"); listBox2.Items.Add("node"); }
//string projectName, Font font, int indent, string ncolor, string scolor, string acolor, string tcolor public static void updateXml(TabControl tabControl, List <string> crayonsSet) { #region writer /*XmlWriterSettings settings = new XmlWriterSettings(); * settings.Indent = true; * XmlWriter writer = XmlWriter.Create(path + "\\config.xml"); * writer.WriteStartDocument(); * writer.WriteStartElement("Settings"); * foreach (TabPage tab in tabControl.TabPages) * { * if(tab.Tag != null) * { * var box = tab.Controls.OfType<RichTextBoxSynchronizedScroll>().First(); * writer.WriteStartElement("Setting"); * writer.WriteElementString("projectName", tab.Tag.ToString()); * writer.WriteElementString("fontSize", box.Font.Size.ToString()); * writer.WriteElementString("fontFamily", box.Font.FontFamily.Name); * writer.WriteElementString("fontStyle", box.Font.Style.ToString()); * //writer.WriteElementString("indent", indent.ToString()); * writer.WriteEndElement(); * * } * * * } * writer.WriteStartElement("Setting"); * writer.WriteElementString("nodeColor", crayonsSet[0]); * writer.WriteElementString("stringColor", crayonsSet[1]); * writer.WriteElementString("attributeColor", crayonsSet[2]); * writer.WriteElementString("textColor", crayonsSet[3]); * writer.WriteEndElement(); * writer.WriteEndElement(); * writer.WriteEndDocument(); * writer.Flush(); * writer.Close();*/ #endregion writer string mark = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); XmlDocument doc = new XmlDocument(); doc.Load(path); doc.RemoveAll(); doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null)); XmlElement root = doc.CreateElement("Settings"); var xsi = "http://www.w3.org/2001/XMLSchema-instance"; XmlAttribute xmlns = doc.CreateAttribute("xmlns:xsd"); xmlns.Value = xsi; root.Attributes.Append(xmlns); xmlns = doc.CreateAttribute("noNamespaceSchemaLocation", xsi); xmlns.Value = "config.xsd"; root.Attributes.Append(xmlns); RichTextBoxSynchronizedScroll fontBox = new RichTextBoxSynchronizedScroll(); XmlElement file = doc.CreateElement("Files"); foreach (TabPage tab in tabControl.TabPages) { if (tab.Tag != null) { var box = tab.Controls.OfType <RichTextBoxSynchronizedScroll>().First(); file.AppendChild(doc.CreateElement("projectName")).InnerText = tab.Tag.ToString(); fontBox = box; } } root.AppendChild(file); XmlElement font = doc.CreateElement("Font"); font.AppendChild(doc.CreateElement("fontSize")).InnerText = fontBox.Font.Size.ToString(); font.AppendChild(doc.CreateElement("fontFamily")).InnerText = fontBox.Font.FontFamily.Name; font.AppendChild(doc.CreateElement("fontStyle")).InnerText = fontBox.Font.Style.ToString(); root.AppendChild(font); XmlElement colors = doc.CreateElement("Colors"); colors.AppendChild(doc.CreateElement("nodeColor")).InnerText = crayonsSet[0]; colors.AppendChild(doc.CreateElement("stringColor")).InnerText = crayonsSet[1]; colors.AppendChild(doc.CreateElement("attributeColor")).InnerText = crayonsSet[2]; colors.AppendChild(doc.CreateElement("textColor")).InnerText = crayonsSet[3]; root.AppendChild(colors); doc.AppendChild(root); doc.Save(path); }
private void loadPrevious() { string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); List<string> xmlPaths; try { if (File.Exists(path + "\\config.xml")) { //do you wanna build a snowman? crayonsSet = xmlHandler.loadColorConfig(); HighLight.config(crayonsSet); listBox1.Font = xmlHandler.loadFontConfig(); wplayer.controls.play(); DialogResult dialog = MessageBox.Show("Do you wanna build a snowman?", "Last session", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { xmlPaths = xmlHandler.XmlLoad(); if (xmlPaths.Count > 0) { foreach (string xmlPath in xmlPaths) { openXMLFile(xmlPath, null); } tabControl1.TabPages.Remove(tabPage1); } focusedRichTextBox.Font = listBox1.Font; Snowman snowman = new Snowman(); snowman.Show(); snowman.TopMost = true; snowman.FormClosed += Snowman_FormClosed; } } else { xmlHandler.createConfig(); crayonsSet = HighLight.defaultColors(); currentTab = tabPage1; focusedRichTextBox = richTextBox1; focusedRichTextBox.MouseWheel += FocusedRichTextBox_MouseWheel; focusedRichTextBox.vScroll += scrollSyncTxtBox1_vScroll; lineNumbering(); } } catch (ArgumentNullException ae) { listBox1.Items.Add("The config was empty, we made you another one."); xmlHandler.createConfig(); crayonsSet = HighLight.defaultColors(); currentTab = tabPage1; focusedRichTextBox = richTextBox1; focusedRichTextBox.MouseWheel += FocusedRichTextBox_MouseWheel; focusedRichTextBox.vScroll += scrollSyncTxtBox1_vScroll; lineNumbering(); } return; }
private void richTextBox_Enter(object sender, EventArgs e) { focusedRichTextBox = (RichTextBoxSynchronizedScroll)sender; }