我设法在C#中动态创建文本框。当textbox
有文字时,我点击它时可以让它消失吗?
我需要在文本框中添加一个单词,这是Oracle中select的结果。
答案 0 :(得分:4)
为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;
}
}
答案 1 :(得分:1)