I have several events of my textbox, the problem is that I have a 30 in my form. I would like to know if there is any way for me to improve my code, reduce it by creating only one method to handle all of those events.
Three TextBox sample events:
private void textEmpPrefixo_KeyUp(object sender, KeyEventArgs e)
{
var elemento = e.OriginalSource as UIElement;
if (e.Key == Key.Down)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
if (e.Key == Key.Up)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
}
}
private void textEmpTelefones_KeyUp(object sender, KeyEventArgs e)
{
var elemento = e.OriginalSource as UIElement;
if (e.Key == Key.Down)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
if (e.Key == Key.Up)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
}
}
private void textEmpObs2_KeyUp(object sender, KeyEventArgs e)
{
var elemento = e.OriginalSource as UIElement;
if (e.Key == Key.Down)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
if (e.Key == Key.Up)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
}
}
I use them to change focus as they use the up or down arrow I use C # wpf technology.
Thank you in advance (: