WinForms event for TextBox focus?

前端 未结 4 986
醉梦人生
醉梦人生 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条回答
  •  臣服心动
    2021-02-07 08:56

    this.tGID.GotFocus += OnFocus;
    this.tGID.LostFocus += OnDefocus;
    
    private void OnFocus(object sender, EventArgs e)
    {
       MessageBox.Show("Got focus.");
    }
    
    private void OnDefocus(object sender, EventArgs e)
    {
        MessageBox.Show("Lost focus.");
    }
    

    This should do what you want and this article describes the different events that are called and in which order. You might see a better event.

提交回复
热议问题