当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Facebook Style Dynamic Dropdown menu on Windows Forms

问题描述:

I would like to have a Facebook style dynamic drop down menu on windows forms using csharp.

Any idea how to implement it?

TextChanged event of text box can be used but I don't know how to visualize it.

For the ones who doesn't use facebook here is the description.

Normally there is no drop down menu, but when you start typing, it shows automatically your friends whose names are matching and as soon as text is changed it updates content of dropdown menu.

Note: If it helps, devexpress tools also can be used.

Thanks&Regards,

-AFgone

网友答案:

Simply use a textbox and a combobox. Start with the combobox invisible and displayed on top of the textbox. As soon as text is entered, make the combobox visible and set the focus to it. Some sample code:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        comboBox1.Visible = false;
        comboBox1.Size = textBox1.Size;
        comboBox1.Location = textBox1.Location;
    }

    private void textBox1_TextChanged(object sender, EventArgs e) {
        if (textBox1.Text.Length > 0) {
            comboBox1.Text = textBox1.Text;
            comboBox1.Visible = true;
            comboBox1.Focus();
            textBox1.Enabled = false;
            // todo: fill combo
        }
    }

    private void comboBox1_Leave(object sender, EventArgs e) {
        comboBox1.Visible = false;
        textBox1.Text = "";
        textBox1.Enabled = true;
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: