winform 与百度搜索智能提示

Posted on 2017-04-12 15:12  熊先生丶  阅读(166)  评论(0编辑  收藏  举报
  private void textBox1_TextChanged(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            if (string.IsNullOrEmpty(textBox1.Text))
            {

                foreach (string str in gz)
                {
                    listBox1.Items.Add(str);

                }

            }
            else
            {

                foreach (string str in gz)
                {  if(str.IndexOf(textBox1.Text)>=0)

                    listBox1.Items.Add(str);

                }
            
            
            
            }

        }

listbox 在用户获取textbox焦点时或text改变时 显示 在 选择或者失去焦掉时 隐藏listbox