2013-02-28 97 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; 
    } 
} 
相關問題