【发布时间】:2013-02-19 10:47:41
【问题描述】:
我在注册表中有 6 个Textbox,其中包含一些预设文本。
当我在Textbox 中单击Name 时,预设文本Enter your full name 应该会消失...如果我随后在Email 中单击Textbox 而不在Name 文本框中写入任何内容,那么Enter your full name 应该再次出现。这个事件应该发生在我所有的Textbox 上,但是它们在每个Textbox 中应该是不同的文本...而不是所有Enter your full name。有人可以帮我吗?
我现在拥有的代码可以在我点击 Textbox 时使用 GotFocus 事件清除它们。
private void textBox1_GotFocus(Object sender, EventArgs e)
{
textBox1.Clear();
}
在文本框中,我有预设文本....我希望每个文本框的确切预设文本在我单击 Textbox 之外时返回。
我听说过“占位符”?
下面是使用额外构造函数后的样子。我不知道我做错了什么?
public partial class CustomTextbox : TextBox
{
private const string _text = @"Enter your full name";
private bool _isEmpty = true;
public CustomTextbox()
{
base.ForeColor = SystemColors.GrayText;
Text = _text;
Leave += LeaveTextBox;
Enter += EnterTextBox;
TextChanged += TextChangedTextBox;
}
public CustomTextbox(string tempText)
{
base.ForeColor = SystemColors.GrayText;
Text = tempText;
Leave += LeaveTextBox;
Enter += EnterTextBox;
TextChanged += TextChangedTextBox;
}
【问题讨论】:
-
我不明白你的确切问题,但为什么不在 lostfocus 上重新填充?
-
你能改写你的问题吗?
-
相信你在找WaterMark,看到这个问题:stackoverflow.com/questions/4902565/…
标签: winforms c#-4.0 textbox onclick