2013-02-28 40 views
1

我设法在C#中动态地创建文本框。当textbox有文字时,点击它可以让它消失吗?如何使文本框文本消失,当我点击它

我需要在文本框内输入一个单词,这是Oracle中选择的结果。

+1

你有没有试过_anything_这么远吗?请阅读[常见问题]和[问] – 2013-02-28 10:50:26

+0

WPF或Winforms? – Lojko 2013-02-28 10:54:41

+1

我用Google搜索了一下,但是我没有找到任何想法。我真的不知道如何创建一个带有文本的文本框。 – Viva 2013-02-28 10:58:32

回答

3

将值赋给TextBox的Text属性。然后,您可以订阅GotFocus事件,并将文本值设置为空字符串。

// Holds a value determining if this is the first time the box has been clicked 
// So that the text value is not always wiped out. 
bool hasBeenClicked = false; 

private void TextBox_Focus(object sender, RoutedEventArgs e) 
{ 
    if (!hasBeenClicked) 
    { 
     TextBox box = sender as TextBox; 
     box.Text = String.Empty; 
     hasBeenClicked = true; 
    } 
} 
相关问题