1

我正在使用代码编辑器(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 事件中。

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

在此处输入图像描述

突出显示已经起作用,但问题是它就像扫描每个文本以突出显示一行。

我应该怎么做才能避免它?

4

0 回答 0