0

就像来自 Avalon 的这张图片: 在此处输入图像描述

如何为上下文提示或智能感知做正确的定位?

情景:

我正在使用代码编辑器,我使用richtextbox(rtb) 作为c 编辑器,使用组合框(lb) 作为上下文提示。

除了组合框(上下文提示)的正确定位之外,所有代码都几乎完成了()。

我使用这个代码:

Point cursorPt = Cursor.Position;
lb.Location = PointToClient(cursorPt);

但是当鼠标光标出现时它会出现......如果鼠标光标在表单之外,它也不会出现。

更多继承人的代码:

 public void TextChangedEvent(object sender, EventArgs e)
    {
        lb.BringToFront();

        RichTextBox rtb = sender as RichTextBox;

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

        // Calculate the starting position of the current line.
        int start = 0, end = 0;
        for (start = rtb.SelectionStart - 1; start > 0; start--)
        {
            if (rtb.Text[start] == '\n') { start++; break; }
        }

        // Calculate the end position of the current line.
        for (end = rtb.SelectionStart; end < rtb.Text.Length; end++)
        {
            if (rtb.Text[end] == '\n') break;
        }

        // Extract the current line that is being edited.
        String line = rtb.Text.Substring(start, end - start);

        // Backup the users current selection point.
        int selectionStart = rtb.SelectionStart;
        int selectionLength = rtb.SelectionLength;

        // Split the line into tokens.
        Regex r = new Regex("([ \\t{}();])");
        Regex singlequote = new Regex("\'[^\"]*\'");
        Regex doublequote = new Regex("\"[^\"]*\"");
        string[] tokens = r.Split(line);
        int index = start;
        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 (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;
            }

            //*** invention code:

            Point cursorPt = Cursor.Position;
            lb.Location = PointToClient(cursorPt);

            KeyWord keywordsL = new KeyWord();
            KeyWord eventsL = new KeyWord();

            if (token == "." || token.StartsWith(".") & token.EndsWith(" "))
            {
                foreach (string str in keywordsL.keywords)
                {
                    lb.Items.Add(str);
                    lb.Visible = true;
                    lb.Focus();

                }

提前!

4

1 回答 1

0
Point point = this.rtb.GetPositionFromCharIndex(rtb.SelectionStart);
this.lb.Location = point;
于 2013-03-20T06:49:28.097 回答