コード例 #1
0
ファイル: Form.cs プロジェクト: blakeknox/CircleCylinder
        //**************************************
        //Procedure: Dispose
        //**************************************

        private void DisposeForm()
        {
            rdoCircle.Checked = true;
            txtVolume.Clear();
            txtArea.Clear();
            txtCircumference.Clear();
            txtHeight.Clear();
            txtRadius.Clear();
            btnDefinition.Enabled = false;
            btnVolume.Enabled     = false;
            btnDispose.Enabled    = false;
            txtError.Text         = "";
            Circles  = null;
            Cylinder = null;
        }
コード例 #2
0
ファイル: Form.cs プロジェクト: blakeknox/CircleCylinder
        private void btnNew_Click(object sender, EventArgs e)
        {
            if (rdoCircle.Checked)
            {
                if (txtRadius.Text.Trim().Length > 0)
                {
                    decimal decRad;
                    if (Circles == null)
                    {
                        try
                        {
                            decRad  = Convert.ToDecimal(txtRadius.Text);
                            Circles = new clsCircle(decRad);
                        }
                        catch (Exception ex)
                        {
                            txtError.Text = "Radius must be numeric." + ex.Message;
                        }
                    }
                    else
                    {
                        txtError.Text = "Circle already exists.";
                    }
                    btnArea.Enabled          = true;
                    btnCircumference.Enabled = true;
                    btnDefinition.Enabled    = true;
                    btnDispose.Enabled       = true;
                    txtCircumference.Text    = Circles.Circumference().ToString();
                    txtArea.Text             = Circles.Area().ToString();
                }
                else
                {
                    txtError.Text = "Radius must be greater then zero.";
                }
            }
            else
            {
                if (txtRadius.Text.Trim().Length > 0 && txtHeight.Text.Trim().Length > 0)
                {
                    decimal decRad;
                    decimal decHgt;

                    if (Cylinder == null)
                    {
                        try
                        {
                            decHgt   = Convert.ToDecimal(txtHeight.Text);
                            decRad   = Convert.ToDecimal(txtRadius.Text);
                            Cylinder = new clsCylinder(decRad, decHgt);
                        }
                        catch (Exception ex)
                        {
                            txtError.Text = "Radius and Height must be numeric." + ex.Message;
                        }
                    }
                    else
                    {
                        txtError.Text = "Cylinder already exists.";
                    }
                    btnArea.Enabled          = true;
                    btnCircumference.Enabled = true;
                    btnDefinition.Enabled    = true;
                    btnDispose.Enabled       = true;
                    btnVolume.Enabled        = true;
                    txtCircumference.Text    = Cylinder.Circumference().ToString();
                    txtArea.Text             = Cylinder.Area().ToString();
                    txtVolume.Text           = Cylinder.Volume().ToString();
                }
                else
                {
                    txtError.Text = "Radius and Height must be greater then zero.";
                }
            }
        }