Exemplo n.º 1
0
 private void MainMenuStrip_Click(object sender, EventArgs e)
 {
     // without this, the main menu strip never receives focus (focus is always on the WebView)
     MainMenuStrip.Focus();
 }
Exemplo n.º 2
0
        //needs work with nested nodes
        //also super slow lol
        private void UpdateSyntaxHighlighting()
        {
            if (IsXml)
            {
                string          nodes            = "<.+?>|\t<.+?>";
                MatchCollection nodeMatches      = Regex.Matches(TextTextBox.Text, nodes);
                string          comments         = "<!--.+?-->";
                MatchCollection commentMatches   = Regex.Matches(TextTextBox.Text, comments);
                string          attributeNames   = " .+?=\"";
                MatchCollection attributeMatches = Regex.Matches(TextTextBox.Text, attributeNames);
                string          strings          = "\".+?\"";
                MatchCollection stringMatches    = Regex.Matches(TextTextBox.Text, strings);

                int   originalIndex  = TextTextBox.SelectionStart;
                int   originalLength = TextTextBox.SelectionLength;
                Color originalColor  = Color.Black;
                MainMenuStrip.Focus();
                TextTextBox.SelectionStart  = 0;
                TextTextBox.SelectionLength = TextTextBox.Text.Length;
                TextTextBox.SelectionColor  = originalColor;

                if (nodeMatches != null)
                {
                    foreach (Match m in nodeMatches)
                    {
                        TextTextBox.SelectionStart  = m.Index;
                        TextTextBox.SelectionLength = m.Length;
                        TextTextBox.SelectionColor  = NodeColor;
                    }
                }

                if (attributeMatches != null)
                {
                    foreach (Match m in attributeMatches)
                    {
                        TextTextBox.SelectionStart  = m.Index;
                        TextTextBox.SelectionLength = m.Length;
                        TextTextBox.SelectionColor  = AttributeColor;
                    }
                }

                if (stringMatches != null)
                {
                    foreach (Match m in stringMatches)
                    {
                        TextTextBox.SelectionStart  = m.Index;
                        TextTextBox.SelectionLength = m.Length;
                        TextTextBox.SelectionColor  = StringColor;
                    }
                }

                if (commentMatches != null)
                {
                    foreach (Match m in commentMatches)
                    {
                        TextTextBox.SelectionStart  = m.Index;
                        TextTextBox.SelectionLength = m.Length;
                        TextTextBox.SelectionColor  = CommentColor;
                    }
                }


                TextTextBox.SelectionStart  = originalIndex;
                TextTextBox.SelectionLength = originalLength;
                TextTextBox.SelectionColor  = originalColor;
                TextTextBox.Focus();
            }
        }