private void WidthTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { bool validWidthType = int.TryParse(WidthTextBox.Text, out int width); if (validWidthType) { if (width < Desk.MINWIDTH || width > Desk.MAXWIDTH) { MessageBox.Show($"Please enter a valid desk width between {Desk.MINWIDTH} and {Desk.MAXWIDTH}.", "Width Input Error"); WidthErrorLabel.Text = $"X {Desk.MINWIDTH}-{Desk.MAXWIDTH} inches"; WidthTextBox.Text = string.Empty; WidthTextBox.BackColor = Color.MistyRose; WidthTextBox.Focus(); } else { WidthTextBox.BackColor = Color.Honeydew; } } else { MessageBox.Show($"Please enter a valid desk width.", "Width Input Error"); WidthTextBox.Text = string.Empty; WidthTextBox.BackColor = Color.MistyRose; WidthTextBox.Focus(); } }
private void validatingWidth(object sender, CancelEventArgs e) { string errorMsg; if (!ValidWidth(WidthTextBox.Text, out errorMsg)) { // Cancel the event and select the text to be corrected by the user. e.Cancel = true; WidthTextBox.Select(0, WidthTextBox.Text.Length); // Set the ErrorProvider error with the text to display. this.widthErrorProvider.SetError(WidthTextBox, errorMsg); } }
private void WidthTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (int.TryParse(WidthTextBox.Text, out int WidthInput)) { if (WidthInput < Desk.MINWIDTH || WidthInput > Desk.MAXWIDTH) { MessageBox.Show("The width of the desk should be more than 24 and less than 96 inches"); WidthTextBox.Text = String.Empty; WidthTextBox.Focus(); } else { } } }
private void WidthBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (int.TryParse(WidthTextBox.Text, out int WidthInput)) { if (WidthInput < Desk.MINWIDTH || WidthInput > Desk.MAXWIDTH) { MessageBox.Text = "Please enter a width from 24 to 96 inches squared."; WidthTextBox.Text = String.Empty; WidthTextBox.BackColor = Color.Red; WidthTextBox.Focus(); } else { WidthTextBox.BackColor = Color.GreenYellow; MessageBox.Text = String.Empty; } } }
private void WidthTextBox_Validating(object sender, CancelEventArgs e) { if (int.TryParse(WidthTextBox.Text, out int WidthInput)) { if (WidthInput < Desk.MINWIDTH || WidthInput > Desk.MAXWIDTH) { MessageBox.Show("Please enter a width from 24 to 96 inches."); WidthTextBox.Text = String.Empty; WidthTextBox.BackColor = Color.Red; WidthTextBox.Focus(); } else { MessageBox.Show("Thank you for entering the width."); WidthTextBox.Text = String.Empty; WidthTextBox.BackColor = Color.White; WidthTextBox.Focus(); } } }
private void WidthTextBox_Validating(object sender, CancelEventArgs e) { if (int.TryParse(WidthTextBox.Text, out int WidthInput)) { if (WidthInput < Desk.MINWIDTH || WidthInput > Desk.MAXWIDTH) { MessageBox.Show("Please enter a width from 24 to 96 inches."); WidthTextBox.Text = String.Empty; WidthTextBox.BackColor = Color.LightSalmon; WidthTextBox.Focus(); } else { WidthTextBox.BackColor = Color.White; } } else { MessageBox.Show("Please enter a valid width measurement as a whole number."); WidthTextBox.Text = ""; WidthTextBox.BackColor = Color.LightSalmon; WidthTextBox.Focus(); } }
private void WidthTextBox_TextChanged(object sender, TextChangedEventArgs e) { WidthTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource(); }
private void WidthTextBox_Enter(object sender, EventArgs e) { WidthTextBox.Clear(); }
private void CalculateBtn_Click(object sender, EventArgs e) { if (int.TryParse(WidthTextBox.Text, out int WidthInput)) { if (WidthInput < Desk.MINWIDTH || WidthInput > Desk.MAXWIDTH) { MessageBox.Show("The width of the desk should be more than 24 and less than 96 inches"); WidthTextBox.Text = String.Empty; WidthTextBox.Focus(); } else { } } try { CustomerName = CustomerNameTextBox.Text; DeskWidth = int.Parse(WidthTextBox.Text); DeskDepth = int.Parse(DepthTextBox.Text); Drawers = int.Parse(NumberOfDrawers.SelectedItem.ToString()); DesktopMaterial = (DesktopMaterial)desktopMaterialBox.SelectedValue; if (rushThreeButton.Checked) { RushOrderDays = 3; } if (rushFiveButton.Checked) { RushOrderDays = 5; } if (rushSevenButton.Checked) { RushOrderDays = 7; } DeskQuote NewQuote = new DeskQuote(CustomerName, DateTime.Now, DeskWidth, DeskDepth, Drawers, DesktopMaterial, RushOrderDays); DeskQuoteTotal = NewQuote.CalculateQuoteTotal(); //build output string using csv var DeskRecord = CustomerName + "," + DateTime.Now + "," + DeskWidth + "," + DeskDepth + "," + Drawers + "," + DesktopMaterial + "," + RushOrderDays + "," + DeskQuoteTotal; string cFile = @"quotes.txt"; if (!File.Exists(cFile)) { using (StreamWriter sw = File.CreateText("quotes.txt")) { } } using (StreamWriter swa = File.AppendText("quotes.txt")) { swa.WriteLine(DeskRecord); } // display quote var MainMenu = (MainMenu)Tag; DisplayQuote displayQuote = new DisplayQuote(NewQuote) { Tag = MainMenu }; displayQuote.Show(); Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }