C# textbox show previous written texts

匆匆过客 提交于 2020-01-21 19:35:09

问题


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:


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



来源:https://stackoverflow.com/questions/11238602/c-sharp-textbox-show-previous-written-texts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!