添加占位符文本到文本框 [英] Adding placeholder text to textbox

查看:210
本文介绍了添加占位符文本到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方式来占位符文本添加到一个文本框,就像你可以在HTML5的一个文本框。

I am looking for a way to add placeholder text to a textbox like you can with a textbox in html5.

即。如果文本框没有文本,然后添加文本在这里输入一些文字,当它在用户点击占位符文本消失,允许用户输入自己的文字,如果文本框失去焦点,仍然没有文本,然后占位符加回到文本框。

I.e. if the textbox has no text, then it adds the text Enter some text here, when the user clicks on it the placeholder text disappears and allows the user to enter their own text, and if the textbox loses focus and there is still no text then the placeholder is added back to the textbox.

推荐答案

那不是仅仅是这样的:

Textbox myTxtbx = new Textbox();
myTxtbx.Text = "Enter text here...";

myTxtbx.GotFocus += GotFocus.EventHandle(RemoveText);
myTxtbx.LostFocus += LostFocus.EventHandle(AddText);

public RemoveText(object sender, EventArgs e)
{
     myTxtbx.Text = "";
}

public AddText(object sender, EventArgs e)
{
     if(String.IsNullOrWhiteSpace(myTxtbx.Text))
        myTxtbx.Text = "Enter text here...";
}

那只是伪code,但这个概念是存在的。

Thats just pseudocode but the concept is there.

这篇关于添加占位符文本到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆