C# 文本框显示以前的书面文本 [英] C# textbox show previous written texts

查看:18
本文介绍了C# 文本框显示以前的书面文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果您访问 facebook 并双击登录文本框,那么会有一些以前有人写的登录.有什么方法可以在 C# 文本框上进行先前输入的下拉列表吗?我不想要组合框.

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.

推荐答案

参见TextBox.AutoCompleteModeTextBox.AutoCompleteSource 文本框的属性.您需要在以下几行中做一些事情:

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;
        }
    }
}

查看以下教程:在 WinForms Windows 中自动完成文本框表格申请

这篇关于C# 文本框显示以前的书面文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆