关于c#的文本框,帮个忙。

来源:百度知道 编辑:UC知道 时间:2024/05/15 03:15:54
我想在c#中实现下述效果:
文本未取得焦点时,上面有提示字符,颜色是灰色,
当用户单击文本框后,提示字符被删除,接着输入的字符是黑色。

比如www.youku.com 上的搜索文本框就是这个效果。
以及百度知道提问中的补充说明对话框也是这样的效果。
我想说是在c#中实现这个。
我是用于编程,不是做网页。

我刚在VS2005里试了下,好像可以达到你的要求。
往Form上添加文本框时设置其ForeColor为灰色(系统的SrollBar就像是灰色)。然后添加初始文本。在textBox1的click事件里加上
this.textBox1 .Text = "";
this.textBox1.ForeColor = Color.Black;
就可以了。不过这样运行的话,出来时初始字符串有被选中时的那种蓝色覆盖。
添加文本框时把它的TabStop设为false就可以了。
我是菜鸟,不知道这样可不可以。

function sr_onfocus(o){
var v = o.value;
if(v.substring(0,3) =="请输入")o.value = ""
o.style.color="#000";
}
<input id="search_input" name="keywords" type="text" value="请输入您想搜索的帮助主题关键字”" onfocus="sr_onfocus(this)" maxLength="50" style="color:#ccc;"/>

<script language="javascript" type="text/javascript">
function Clear()
{
var test1 = document.getElementById("txtTest1");
test1.value="";
}

</script>
<input id="txtTest1" name="txtTest1"