private void SelectionChangedMethod(object sender, SelectionChangedEventArgs e) { if ((sender as ComboBox).SelectedItem != null) { userUpdate = false; UserInputTextBox.Text = (sender as ComboBox).SelectedItem.ToString(); UserInputTextBox.CaretIndex = UserInputTextBox.Text.Length; UserInputTextBox.Focus(); InputCacheComboBox.IsDropDownOpen = false; userUpdate = true; } }
private void KeyDownComboBoxMethod(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { UserInputTextBox.Focus(); InputCacheComboBox.IsDropDownOpen = false; } else if (e.Key != Key.Up && e.Key != Key.Down && e.Key != Key.Enter) { UserInputTextBox.Focus(); } }
private void ClearFormToolStripMenuItem_Click(object sender, EventArgs e) { UserInputTextBox.Clear(); InitialValueLabel.Hide(); InitialUnitsLabel.Hide(); EqualsLabel.Hide(); ResultingUnitsLabel.Hide(); ResultingValueLabel.Hide(); UserInputTextBox.Focus(); }
private void KeyDownMethod(object sender, KeyEventArgs e) { if (e.Key == Key.Down) { FilterItems(string.Empty); InputCacheComboBox.IsDropDownOpen = true; InputCacheComboBox.Focus(); } else if (e.Key == Key.Escape) { UserInputTextBox.Focus(); InputCacheComboBox.IsDropDownOpen = false; } }
private void UserInputTextBox_GotFocus(object sender, RoutedEventArgs e) { userUpdate = true; if (!expanded && string.IsNullOrWhiteSpace(UserInputTextBox.Text)) { FilterItems(UserInputTextBox.Text); if (suggestList.Count > 0) { InputCacheComboBox.IsDropDownOpen = true; UserInputTextBox.Focus(); expanded = true; } } }
//Shows Converter Menu private void ShowConverter() { //Show the converter menu's controls and labels CategoryLabel.Show(); CategoryComboBox.Show(); InstructionLabel.Show(); ValueOfLabel.Show(); UserInputTextBox.Show(); FromLabel.Show(); InitialUnitsComboBox.Show(); ToLabel.Show(); ResultingUnitsComboBox.Show(); BackButtonLabel.Show(); BackButton.Show(); DividerLabel.Show(); UserInputTextBox.Focus(); }
//Overrided method accepting a category parameter obtained from menu selection private void ShowConverter(String category) { //Shows the converter menu's controls and labels CategoryLabel.Show(); CategoryComboBox.Show(); InstructionLabel.Show(); ValueOfLabel.Show(); UserInputTextBox.Show(); FromLabel.Show(); InitialUnitsComboBox.Show(); ToLabel.Show(); ResultingUnitsComboBox.Show(); ConvertSubmissionButton.Show(); BackButtonLabel.Show(); BackButton.Show(); DividerLabel.Show(); //Selects the category field in the converter CategoryComboBox.SelectedIndex = CategoryComboBox.FindStringExact(category); //Shows the default units of measurement ShowDefaultUnits(category); UserInputTextBox.Focus(); }
//add to order button event handling private void AddToOrderButton_Click(object sender, EventArgs e) { //declaration int Identify; //gets the available stock for the choosen option AvailableStock = (StockList2DArray[GetMealSizeIndex, GetMealTypeIndex]); try { //tries to parse user input to an integer UserInputQuantity = int.Parse(UserInputTextBox.Text); if (UserInputQuantity > 0) //checks if the input is greater than zero { //if what the user enters is equal to or less than the avalable stock if (UserInputQuantity <= AvailableStock) { DisplayPrice.Text = (UserInputQuantity * Cost).ToString(); MealTypeChoosen.Add((MealTypeListBox.SelectedItem).ToString()); MealSizeChoosen.Add((MealSizeListBox.SelectedItem).ToString()); QuantityChoosen.Add(UserInputQuantity); PriceOfChoice.Add(decimal.Parse(DisplayPrice.Text)); RunningTotal += UserInputQuantity * Cost; TotalPriceLabel.Text = RunningTotal.ToString(); CompleteOrderButton.Enabled = true; ClearButton.Enabled = true; //------------------------------------- for (Identify = MealTypeChoosen.Count - 1; Identify != MealTypeChoosen.Count; Identify++) { OrderListBox.Items.Add(MealTypeChoosen.ElementAt(Identify) + "\t" + MealSizeChoosen.ElementAt(Identify) + "\t" + QuantityChoosen.ElementAt(Identify) + "\t" + Cost.ToString() + "\t" + PriceOfChoice.ElementAt(Identify).ToString("C")); (StockList2DArray[GetMealSizeIndex, GetMealTypeIndex]) = AvailableStock - UserInputQuantity;// this should work else i am in for it } //OrderListBox.ClearSelected(); MealTypeListBox.SelectedIndex = -1; MealSizeListBox.SelectedIndex = -1; DisplayPrice.Text = ""; UserInputTextBox.Text = ""; } else// if the user input doesn't meet the above conditions i.e, greater than the available stock { MessageBox.Show("the available stock is:" + AvailableStock, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); UserInputTextBox.Text = AvailableStock.ToString(); UserInputTextBox.Focus(); UserInputTextBox.SelectAll(); DisplayPrice.Text = ""; } } else { //if the user input is negative or inavlid MessageBox.Show("Please enter a valid quantity", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Warning); UserInputTextBox.Focus(); UserInputTextBox.SelectAll(); } } catch //if user input can't be parsed { MessageBox.Show("Please enter a quantity greater than 1", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); UserInputTextBox.Focus(); UserInputTextBox.SelectAll(); } }