コード例 #1
0
        private void DepthTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            bool validDepthType = int.TryParse(WidthTextBox.Text, out int depth);

            if (validDepthType)
            {
                if (depth < Desk.MINDEPTH || depth > Desk.MAXDEPTH)
                {
                    MessageBox.Show($"Please enter a valid desk width between {Desk.MINDEPTH} and {Desk.MAXDEPTH}.", "Width Input Error");
                    DepthErrorLabel.Text   = $"X {Desk.MINDEPTH}-{Desk.MAXDEPTH} inches";
                    DepthTextBox.Text      = string.Empty;
                    DepthTextBox.BackColor = Color.MistyRose;
                    DepthTextBox.Focus();
                }
                else
                {
                    DepthTextBox.BackColor = Color.Honeydew;
                }
            }
            else
            {
                MessageBox.Show($"Please enter a valid desk width.", "Width Input Error");
                DepthTextBox.Text      = string.Empty;
                DepthTextBox.BackColor = Color.MistyRose;
                DepthTextBox.Focus();
            }
        }
コード例 #2
0
 private void DepthTextBox_Validating(object sender, CancelEventArgs e)
 {
     if (int.TryParse(DepthTextBox.Text, out int height))
     {
         if (height < Desk.MINDEPTH || height > Desk.MAXDEPTH)
         {
             MessageBox.Show("Please enter a width from 24 to 48 inches.");
             DepthTextBox.Text      = String.Empty;
             DepthTextBox.BackColor = Color.LightSalmon;
             DepthTextBox.Focus();
         }
     }
     else
     {
         MessageBox.Show("Please enter a valid width measurement as a whole number.");
         DepthTextBox.Text      = "";
         DepthTextBox.BackColor = Color.LightSalmon;
         DepthTextBox.Focus();
     }
 }
コード例 #3
0
 private void DepthTextBox_Validating(object sender, CancelEventArgs e)
 {
     if (int.TryParse(DepthTextBox.Text, out int DepthInput))
     {
         if (DepthInput < Desk.MINDEPTH || DepthInput > Desk.MAXDEPTH)
         {
             MessageBox.Show("Please enter a depth from 24 to 48 inches.");
             DepthTextBox.Text      = String.Empty;
             DepthTextBox.BackColor = Color.Red;
             DepthTextBox.Focus();
         }
         else
         {
             DepthTextBox.BackColor = Color.White;
         }
     }
     else
     {
         MessageBox.Show("Thank you for entering the width.");
         DepthTextBox.Text      = String.Empty;
         DepthTextBox.BackColor = Color.LightSalmon;
         DepthTextBox.Focus();
     }
 }