Puoi registrare i rispettivi eventi in questo modo:
private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.GotFocus += new EventHandler(textBox1_GotFocus);
this.textBox1.LostFocus += new EventHandler(textBox1_LostFocus);
}
void textBox1_LostFocus(object sender, EventArgs e)
{
Console.WriteLine ("LostFocus");
}
void textBox1_GotFocus(object sender, EventArgs e)
{
Console.WriteLine ("GotFocus");
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
this.textBox1.GotFocus -= new EventHandler(textBox1_GotFocus);
this.textBox1.LostFocus -= new EventHandler(textBox1_LostFocus);
}
Invece di questi eventi, potresti/dovresi utilizzare gli eventi Enter,Leave,Validating, Validated.