Torna al Thread
public frmMain()
{
//Inizializzo i componenti
InitializeComponent();
//per ogni controllo contenuto nella classe frmMain
foreach (Control control in this.Controls)
{
//se il controllo è una textBox
if (control is TextBox)
{
//creo una variabile di tipo TextBox generale
TextBox ctrlCurrent = (control as TextBox);
//creo la "delega" degli eventi del mio TextBox a tutti i controlli di tipo TextBox contenut nella classe frmMain
ctrlCurrent.GotFocus += new EventHandler(ctrlCurrent_GotFocus);
ctrlCurrent.LostFocus += new EventHandler(ctrlCurrent_LostFocus);
}
}
}
//EVENTI GENERALIZZATI PER LE TEXBOX
private void ctrlCurrent_LostFocus(object sender, EventArgs e)
{
(sender as Control).BackColor = Color.White;
}
private void ctrlCurrent_GotFocus(object sender, EventArgs e)
{
(sender as TextBox).SelectionStart = 0;
(sender as TextBox).SelectionLength = (sender as Control).Text.Length;
(sender as Control).BackColor = Color.Yellow;
}