Remove text after clicking in the textbox

后端 未结 8 1009
孤独总比滥情好
孤独总比滥情好 2021-02-02 18:03

When you activate an application, a textbox with text \"hello\" will appear.

My question is:
When you click on the textbox in order to make input data, I want to rem

8条回答
  •  滥情空心
    2021-02-02 18:26

    I want to update Donut's answer.(applicable for windows 8)

    Code behind code be

    public void TextBox_GotFocus(object sender, RoutedEventArgs e)
    {
    
       TextBox tb = (TextBox)sender;
    
       if(tb.Text != "SOME DEFAULT TEXT")
       {
    
         String persentContentWithDefaultString = t.Text as string;
         tb.Text = persentContentWithDefaultString[0].ToString();
         // set cursor position 
          tb.Select(1, 0);         
    
          tb.GotFocus -= TextBox_GotFocus;
     }
    }
    

    Actully in my page , there were two textbox and one button. [Username,pass,and click button]. By default , focus goes to my first textbox and User was not able to see the default text.

提交回复
热议问题