例如,如果你去Facebook并按下双击登录文本框,那么有一些登录以前有人写过。有没有办法在C#文本框中输入以前输入的下拉列表?我不想要组合框。
答案 0 :(得分:4)
请参阅TextBox的TextBox.AutoCompleteMode和TextBox.AutoCompleteSource属性。你需要在以下几行做一些事情:
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;
}
}
}
请查看以下教程:AutoComplete TextBox In WinForms Windows Forms Application