WinForms event for TextBox focus?

前端 未结 4 994
醉梦人生
醉梦人生 2021-02-07 08:13

I want to add an even to the TextBox for when it has focus. I know I could do this with a simple textbox1.Focus and check the bool value... but I don\'

4条回答
  •  Happy的楠姐
    2021-02-07 08:55

    Here is how you wrap it and declare the handling function, based on Hans' answer.

    namespace MyNameSpace
    {
     public partial class Form1 : Form
     {
      public Form1()
      {
       InitializeComponent();
      }
    
      private void Form1_Load(object sender, EventArgs e)
      {
       txtSchedNum.Enter += new EventHandler(txtSchedNum_Enter);
      }
      protected void txtSchedNum_Enter(Object sender, EventArgs e)
      {
       txtSchedNum.Text = "";
      }
     }
    }
    

提交回复
热议问题