怎么用TextBox实现一个输入提示的功能,用的是WinFrom窗体不是网页

怎么用TextBox实现一个输入提示的功能,用的是WinFrom窗体不是网页,第1张

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

}

这个用javascript判断下也可以的

双击按钮 写个onclick事件也行

你双击按钮 然后输入下面代码判断下就行了:

if(textbox1.text=="")

{

response.write("<script language='javascript'>alert('请输入数据')</sccript>

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/bake/11793559.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存