3
I put an event KeyDown
in a field TextBox
for when the user presses Enter, there must be some action.
In this action, I’ve asked for a message to appear Dialog
, but the problem is that if the user presses twice fast the key Enter, the message will appear twice on the screen and this will cause the system to lock.
Is there a solution for this? how to block the enter key when the user is typing for the second time while it is already open? or another solution?
Press Enter on "Average Score":
Dialog:
public async Task mensagemSimples(TextBox text, string titulo, string mensagem)
{
var metroWindow = (Application.Current.MainWindow as MetroWindow);
await metroWindow.ShowMessageAsync(titulo, mensagem);
text.Focus();
text.SelectAll();
}
When I call her:
private async void textRespPontuacaoMed_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
int min = Convert.ToInt32(textRespPontuacaoMin.Text);
int med = Convert.ToInt32(textRespPontuacaoMed.Text);
if (med < min)
{
await mensagemSimples(textRespPontuacaoMed, "Atenção", "Pontuação Média deve ser maior que a Pontuação Mínima");
e.Handled = false;
}else
textRespPontuacaoMax.Focus();
}
}
Thanks.