您的位置:首页 > 其它

Win8 在TextBox中设置提示信息,当TextBox获得焦点时消失,失去时验证

2012-12-20 17:20 190 查看
// 在获得焦点时,验证文本内容是否与提示信息相同,相同则清除,并改变文本颜色

private void email_GotFocus(object sender, RoutedEventArgs e)
{
if (this.email.Text.Equals("email@example.com"))
{
this.email.Text = "";
}
this.email.Foreground = new SolidColorBrush(Colors.Black);
}


// 在失去焦点时,验证文本内容是否为空(清除空格),为空则重新设置提示信息,并改变颜色

private void email_LostFocus(object sender, RoutedEventArgs e)
{
if (0 == this.email.Text.Trim().Length)
{
this.email.Text = "email@example.com";
this.email.Foreground = new SolidColorBrush(Colors.Gray);
}
}


// 效果图



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐