Winform中可以使用webService服务来做.
第一步,创建webservice
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Namespace = "
http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string[] HelloWorld(string ss)
{
//查询相关信息放入数组
return 数组;
}
}
第二步,要使用textbox,则需ListBox的支持,具体操作:
在textbox下方有一个隐藏的ListBox,当在textbox输入值时,调用服务返回值要在Listbox中显示,同时要ListBox显示.
第三步,在TextBox的TextChanged事件里做提示:
private void textBox1_TextChanged(object sender, EventArgs e)
{
//调用webservice
//返回结果添加到ListBox
//ListBox.Visible = true;
}
第四步,在listbox项选择事件里添加:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = listBox1.SelectedItem.ToString();
listBox1.Visible = false;
}