C# textbox show previous written texts

2019-03-02 10:49发布

For example if you go to facebook and press double click on the login textbox, then there are some Logins that previous someone wrote. Is there any way to make this dropdown of previous inputs on C# textbox? I don't want combobox.

1条回答
家丑人穷心不美
2楼-- · 2019-03-02 11:10

See the TextBox.AutoCompleteMode and TextBox.AutoCompleteSource properties of the TextBox. You need to do something on the following lines:

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        AutoCompleteStringCollection autoComplete = new AutoCompleteStringCollection();
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            autoComplete.Add(textBox1.Text);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            //auto.Add(textBox1.Text);
            textBox1.AutoCompleteCustomSource = autoComplete;
        }
    }
}

Check the following Tutorial: AutoComplete TextBox In WinForms Windows Forms Application

查看更多
登录 后发表回答