예제 #1
0
        }        // isValidData

//----------------------------------------------

        private void buttonOk_Click(object sender, System.EventArgs e)
        {
            errorProvider1.Dispose();
            labelsize.Text = "";

            if (numBalls > 0)
            {
                RemoveControls();                // remove last TextBoxes & Lables
                buttonFinish.Visible = false;
            }


            try
            {
                numBalls = int.Parse(textBoxNumBalls.Text);
                if (numBalls > 0)
                {
                    labelsize.Text = "Table.Width = " + BilliardForm.width + "    " +
                                     "Table.Height = " + BilliardForm.height;

                    Initialize(numBalls);
                }
                else
                {
                    errorProvider1.SetError(textBoxNumBalls, "It must be positive!");
                }
            }
            catch
            {
                errorProvider1.SetError(textBoxNumBalls, "Bad Number!");
            }
        }
 private static void TryDispose(ErrorProvider errorProvider)
 {
     if (!(errorProvider.Tag is int))
         return;
     var count = (int)errorProvider.Tag - 1;
     if (count == 0)
         errorProvider.Dispose();
     else
         errorProvider.Tag = count;
 }
예제 #3
0
        private void buttonOk_Click(object sender, System.EventArgs e)
        {
            errorProvider1.Dispose();
            isOkPerresdFormRandomDistribution = false;


            isEveryThingCorrect = true;

//----------------------------------------
            try
            {
                numBalls = int.Parse(textBoxNumBalls.Text);
                if (numBalls <= 0)
                {
                    isEveryThingCorrect = false;
                    errorProvider1.SetError(textBoxNumBalls, "Bad value!");
                }
            }
            catch
            {
                isEveryThingCorrect = false;
                errorProvider1.SetError(textBoxNumBalls, "Bad value!");
            }



            try
            {
                radius = float.Parse(textBoxRadius.Text);
                if (radius <= 0)
                {
                    isEveryThingCorrect = false;
                    errorProvider1.SetError(textBoxRadius, "Bad value!");
                }
            }
            catch
            {
                isEveryThingCorrect = false;
                errorProvider1.SetError(textBoxRadius, "Bad value!");
            }

            if (numBalls * 2 * radius * 2 * radius >= BilliardForm.height * BilliardForm.width -
                Math.Min(BilliardForm.height, BilliardForm.width) * radius)
            {
                isEveryThingCorrect = false;
                errorProvider1.SetError(textBoxNumBalls, "Bad value!");
                errorProvider1.SetError(textBoxRadius, "Bad Value!");

                string error = "This balls can not been in Table." +
                               "\r\nThe Size of form is :\r\n" + "Width = " +
                               BilliardForm.width.ToString() + "  Height = " +
                               BilliardForm.height.ToString();
                MessageBox.Show(error, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }



            try
            {
                maxSpeed = float.Parse(textBoxMaxSpeed.Text);
                if (maxSpeed < 0)
                {
                    isEveryThingCorrect = false;
                    errorProvider1.SetError(textBoxMaxSpeed, "Bad value!");
                }
            }
            catch
            {
                isEveryThingCorrect = false;
                errorProvider1.SetError(textBoxMaxSpeed, "Bad value!");
            }
            try
            {
                minSpeed = float.Parse(textBoxminSpeed.Text);
                if (minSpeed < 0 || minSpeed > maxSpeed)
                {
                    isEveryThingCorrect = false;
                    errorProvider1.SetError(textBoxminSpeed, "Bad value!");
                }
            }
            catch
            {
                isEveryThingCorrect = false;
                errorProvider1.SetError(textBoxminSpeed, "Bad value!");
            }



            try
            {
                mueG = float.Parse(textBoxMueG.Text);
                if (mueG < 0)
                {
                    isEveryThingCorrect = false;
                    errorProvider1.SetError(textBoxMueG, "Bad value!");
                }
            }
            catch
            {
                isEveryThingCorrect = false;
                errorProvider1.SetError(textBoxMueG, "Bad value!");
            }
//-----------------------


            isRandomColor = radioButton2.Checked;
            isBlueColor   = radioButton1.Checked;

            if (isEveryThingCorrect)
            {
                isOkPerresdFormRandomDistribution = true;
                this.Close();
            }
        }
예제 #4
0
        private void buttonOk_Click(object sender, System.EventArgs e)
        {
            bool iseveryThingCorrect = true;

            errorProvider1.Dispose();

            try
            {
                this.speed = float.Parse(textBoxSpeed.Text);
                if (this.speed < 0)
                {
                    iseveryThingCorrect = false;
                    errorProvider1.SetError(textBoxSpeed, "Speed must be positive!");
                }
            }
            catch
            {
                iseveryThingCorrect = false;
                errorProvider1.SetError(textBoxSpeed, "Bad value!");
            }

            try
            {
                this.angle = float.Parse(textBoxAngle.Text);
            }
            catch
            {
                iseveryThingCorrect = false;
                errorProvider1.SetError(textBoxAngle, "Bad value!");
            }

            try
            {
                this.mueg = float.Parse(textBoxmueG.Text);
                if (this.mueg < 0)
                {
                    iseveryThingCorrect = false;
                    errorProvider1.SetError(textBoxmueG, "Coefficient must be positive!");
                }
            }
            catch
            {
                iseveryThingCorrect = false;
                errorProvider1.SetError(textBoxmueG, "Bad value!");
            }

            try
            {
                this.radius = float.Parse(textBoxRadius.Text);
                if (this.radius <= 0)
                {
                    iseveryThingCorrect = false;
                    errorProvider1.SetError(textBoxRadius, "Radius must be positive!");
                }
            }
            catch
            {
                iseveryThingCorrect = false;
                errorProvider1.SetError(textBoxRadius, "Bad value!");
            }


            this.color = colorDialog1.Color;

            if (iseveryThingCorrect)
            {
                this.Close();
            }
        }