當前位置:編程學習大全網 - 編程軟體 - 怎麽用TextBox實現壹個輸入提示的功能,用的是WinFrom窗體不是網頁

怎麽用TextBox實現壹個輸入提示的功能,用的是WinFrom窗體不是網頁

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;

}

  • 上一篇:IC卡是什麽卡?
  • 下一篇:大學生在校期間如何利用空閑時間充實自己?
  • copyright 2024編程學習大全網