提高突出显示的性能[每一行]

时间:2013-05-13 11:17:18

标签: c# visual-studio-2010

我正在编写代码编辑器(winforms),并使用令牌参数进行突出显示,例如:

     foreach (string token in tokens)
            {
                // Set the token's default color and font.
                rtb.SelectionStart = index;
                rtb.SelectionLength = token.Length;
                rtb.SelectionColor = Color.Black;
                rtb.SelectionFont = new Font("Courier New", 10, FontStyle.Regular);

                if (rtb != null)
                {
                    //pass through to the HighlightType class
                    HighlighType HighlighType = new HighlighType(rtb);
                    lb.Hide();
                    lb.Items.Clear();   
                }

                if (token == "//" || token.StartsWith("//"))
                {
                    // Find the start of the comment and then extract the whole comment.
                    int length = line.Length - (index - start);
                    string commentText = rtb.Text.Substring(index, length);
                    rtb.SelectionStart = index;
                    rtb.SelectionLength = length;
                    HighlighType.commentsType(rtb);
                    break;
                }

var keywordsDef = new KeyWord();
            String[] keywords = keywordsDef.keywords;

            for (int i = 0; i < keywords.Length; i++)
            {
                if (keywords[i] == token)
                {
                    // Apply alternative color and font to highlight keyword.        
                    HighlighType.keywordsType(rtb);

                    toolTip1.Show("this is a keyword", rtb); //&
                    break;
                }
            }

if (token == "letterA" || token.StartsWith("ab") || token.StartsWith("Ab") || token.StartsWith("AB"))
            {
                int length = line.Length - (index - start);
                string commentText = rtb.Text.Substring(index, length);
                rtb.SelectionStart = index;
                rtb.SelectionLength = length;
                lb.Visible = true;
                int i = commentText.IndexOf(token);

                KeyWord_Ab newCode = new KeyWord_Ab();



            }

在textchanged事件中。

但每次按“空格”时,光标行中的所有文字都会突出显示如下:

enter image description here

突出显示已经有效,但问题是它就像扫描每一个要突出显示的文本一样。

我该怎么做才能避免它?有什么建议吗?任何帮助都会得到很好的赞赏。真的需要帮助这么糟糕。谢谢!

0 个答案:

没有答案