资源简介

c# winform RichTextBox Autocomplete 自动完成 智能输入

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Intellisense
{
    public partial class MainForm : Form
    {
        public int CurrentTagStart = 0;
        public string intellisenseBuffer = ““;
        public bool PassInputToTextbox = true;

        public MainForm()
        {
            InitializeComponent();
        }

        private void rtbInput_PreviewKeyDown(object sender PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.OemPeriod && e.Shift == false)
            {
                CurrentTagStart = rtbInput.Selectionstart;
                Point p = rtbInput.GetPositionFromCharIndex(rtbInput.Selectionstart);
                p.Y += (int)rtbInput.Font.GetHeight()*2;
                Console.WriteLine((int)rtbInput.Font.GetHeight());
                lbIntelli.Location = p;
                lbIntelli.Show();
                ActiveControl = lbIntelli;
            }
        }

        private void lbIntelli_KeyUp(object sender KeyEventArgs e)
        {
            object ObjToSelect = new object();
            if (e.KeyCode != Keys.OemPeriod)
                if (e.KeyCode != Keys.Back)
                {
                    bool startswith = false;
                    intellisenseBuffer += e.KeyCode;
                    foreach (object obj in lbIntelli.Items)
                    {
                        string str = obj.ToString();
                        if (str != ““)
                        {
                            startswith = str.StartsWith(intellisenseBuffer true null);
                            if (startswith == true)
                            {
                                ObjToSelect = obj;
                                break;
                            }
                        }
                    }
                    if (startswith == false)
                    {
                        intellisenseBuffer = ““;
                        lbIntelli.Hide();
                    }
                    lbIntelli.SelectedItem = ObjToSelect;
                }
                if (e.KeyCode == Keys.Back) { rtbInput.Text.Remove(rtbInput.Selectionstart-11); }
                if (e.KeyCode == Keys.Return)
                {
                    rtbInput.Select(CurrentTagStart+1 rtbInput.Selectionstart);
                    rtbInput.SelectedText = lbIntelli.SelectedItem.ToString();
                }

        }

        private void lbIntelli_KeyPress(object sender KeyPressEventArgs e)
        {
            rtbInput.SelectedText = e.KeyChar.ToString();
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件         929  2006-02-24 11:45  Intellisense\Intellisense.sln
     文件       15360  2006-02-24 11:45  Intellisense\Intellisense.suo
     目录           0  2006-02-24 11:44  Intellisense\Intellisense\
     目录           0  2006-02-24 11:44  Intellisense\Intellisense\bin\
     目录           0  2006-02-24 11:44  Intellisense\Intellisense\bin\Debug\
     文件       24576  2006-02-24 11:42  Intellisense\Intellisense\bin\Debug\Intellisense.exe
     文件        5632  2005-09-23 06:56  Intellisense\Intellisense\bin\Debug\Intellisense.vshost.exe
     目录           0  2006-02-24 11:44  Intellisense\Intellisense\bin\Release\
     文件        2758  2006-02-24 11:44  Intellisense\Intellisense\Form1.cs
     文件        4890  2006-02-24 10:50  Intellisense\Intellisense\Form1.Designer.cs
     文件        5814  2006-02-24 10:50  Intellisense\Intellisense\Form1.resx
     文件        3231  2006-02-24 11:45  Intellisense\Intellisense\Intellisense.csproj
     文件         482  2006-02-24 10:19  Intellisense\Intellisense\Program.cs
     目录           0  2006-02-24 11:44  Intellisense\Intellisense\Properties\
     文件        1272  2006-02-24 10:17  Intellisense\Intellisense\Properties\AssemblyInfo.cs
     文件        2851  2006-02-24 10:18  Intellisense\Intellisense\Properties\Resources.Designer.cs
     文件        5612  2006-02-24 10:17  Intellisense\Intellisense\Properties\Resources.resx
     文件        1095  2006-02-24 10:18  Intellisense\Intellisense\Properties\Settings.Designer.cs
     文件         249  2006-02-24 10:17  Intellisense\Intellisense\Properties\Settings.settings

评论

共有 条评论