SelectAll

  • Thread starter Thread starter Peter Morris [Droopy eyes software]
  • Start date Start date
P

Peter Morris [Droopy eyes software]

Is there any easy way in my form class to ensure that whenever any TextBox
receives focus to call FocussedControl.SelectAll()?

Thanks

Pete
 
Have you tried something like the following:

private void control_GotFocus(object sender, EventArgs e)
{
TextBox text = (TextBox)sender;
text.SelectAll();

}

Of course you need to register each TextBox object with the above event
handler.

Simon.
 
Hi Simon

I wanted a more generic way than this because this is how my app works

1) There is only 1 form
2) It hass a wizard-like interface (next / back)
3) Whenever the current step changes a UI factory will create a UserControl
to represent it
4) The form will remove the current UserControl and replace it with the new
one

So I don't have explicit knowledge of the controls on my form.

Thanks

Pete
 
Not sure I fully understand what you are trying to do. But have you
considered iterating the Controls collection when you create the UserControl
and register the generic event handler for type TextBox.

Simon.
 
Back
Top