2

In C#, what event do you attach an event to for when a textbox loses focus? My function would be something like this:

private void txtModifier1_Blur(object sender, EventArgs e)
{
    // code...
}

... and I would assign it like this:

this.txtModifier1.Blur += new System.EventHandler(this.txtModifier1_Blur);

... but there is no Blur. Any ideas?

gideon
  • 19,329
  • 11
  • 72
  • 113
theundertaker
  • 99
  • 2
  • 11

3 Answers3

3

Assuming this is Windows Forms, you're looking for the Leave event.

kprobst
  • 16,165
  • 5
  • 32
  • 53
2

If you're using the Windows forms TextBox control. It has a LostFocus event, inherited from Control. There is also the Leave event. You should use the Leave event in most cases. See the notes on both the MSDN pages I've linked.

Something like this:

this.txtModifier1.Leave += new System.EventHandler(this.txtModifier1_Leave);

If you're using the WPF TextBox, then again, it has a LostFocus event inherited from UIElement

gideon
  • 19,329
  • 11
  • 72
  • 113
2

Lost Focus for asp.net textbox?

Lost Focus for WPF

Lost Focus for WinForms

Community
  • 1
  • 1
Ilya Ivanov
  • 23,148
  • 4
  • 64
  • 90