I have been trying to stop adding numbers once it hits 30 or goes over 30 (max capacity). My code runs and adds numbers just fine. My issue is how to stop it from getting more numbers once it hits 30 or goes more than 30.
private void ClickToAddMoreCoins(object sender, RoutedEventArgs e)
{
//Hides InputBox and takes input text from user.
InputBox.Visibility = System.Windows.Visibility.Collapsed;
// Ensuring that input from user is a integer number
String input = InputTextBox.Text;
var result = 0;
if (int.TryParse(input, out result))
{
//Adding number of coins to CoinListBox
//CoinListBox.Items.Add(result);
sum += result;
try
{
CoinListBox.Items.RemoveAt(0);
}
catch
{ }
CoinListBox.Items.Add(sum);
}
else
{
MessageBox.Show("Please enter a number of coins");
}
//sum = CoinListBox.Items.Cast<object>().Sum(x => Convert.ToInt32(x));
if(sum > 30)
{
//CoinListBox.Items.Add
MessageBoxResult answer = MessageBox.Show("You cannot enter more than 30 coins. Do you want to end?", "Message", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (answer == MessageBoxResult.Yes)
{
Application.Current.Shutdown();
}
}
// Resets InputBox.
InputTextBox.Text = String.Empty;
}
//This method hides InputBox.
}