Maskedtextbox and SelectAll()

I had a problem with maskedit and the selectAll. I wanted that when clicked on maskedit, all text was selected. The problem had a simply solution: I had to use the SelectAll() method in the Focus Event

.
.
.
mskBox.GotFocus += new EventHandler(mskBox_GotFocus);
.
.
.
.
void mskBox_GotFocus(object sender, EventArgs e)
{
  mskBox.SelectAll();
}

But this did not run. I found this solution:
Maskedtextbox and SelectAll()

private delegate void SetMaskedTextBoxSelectAllDelegate(MaskedTextBox txtbox);

private void maskedTextBox1_Enter(object sender, EventArgs e)
{
   this.BeginInvoke(new SetMaskedTextBoxSelectAllDelegate(SetMaskedTextBoxSelectAll), new object[] { (MaskedTextBox) sender });
}

private void SetMaskedTextBoxSelectAll(MaskedTextBox txtbox)
{
   txtbox.SelectAll();
}

And this run!!!!!

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...