Reputation: 15
I am working on an assignment for school. The goal is to loop a window with the value of a textbox till I enter the value "0" in it.
private void btnGo_Click(object sender, RoutedEventArgs e)
{
Do
{
// code
}
While(tbInput.Text != "0")
}
My problem is that I can't figure out how to solve this. When I enter a value in the textbox and press the button, the window (sort of) freezes. This is because the code keeps looping with the same value that I put in the textbox. How can I make it available to add a new value in the textbox at the start of the Do-While loop?
Upvotes: 1
Views: 278
Reputation: 77926
You don't need a do .. while
loop here since you are checking that on button click. So you can just check for the textbox value and if doesn't match then return a messagebox saying doesn't match and retain focus to the textbox.
private void btnGo_Click(object sender, RoutedEventArgs e)
{
if(tbInput.Text != "0")
{
MessageBox.Show("Doesn't Match...");
FocusManager.SetFocusedElement(parentElement, tbInput);
}
}
Upvotes: 1