【问题标题】:Right Positioning For Context-Hint List (Intellisense)上下文提示列表的正确定位(智能感知)
【发布时间】:2013-03-07 05:30:40
【问题描述】:

就像 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();

                }

提前!

【问题讨论】:

    标签: c#


    【解决方案1】:
    Point point = this.rtb.GetPositionFromCharIndex(rtb.SelectionStart);
    this.lb.Location = point;
    

    【讨论】:

      猜你喜欢
      • 2013-12-01
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-25
      • 2011-02-25
      • 1970-01-01
      相关资源
      最近更新 更多