Exemplo n.º 1
0
        private void btnDraw_Click(object sender, EventArgs e)
        {
            try
            {
                Color c = Color.Black;

                //If all or any of the scale parameters are zero
                if (((int)NUDXmax.Value == 0) || ((int)NUDXmin.Value == 0) || ((int)NUDYmax.Value == 0) || ((int)NUDYmin.Value == 0))
                {
                    //Messagebox is displayed
                    MessageBox.Show("The scale parameters set is invalid. Please refine scale parameters", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //If none of the functions are selected
                if ((RBLinear.Checked == false) && (RBQuadratic.Checked == false) && (RBAbsolute.Checked == false) && (RBRoot.Checked == false) && (RBCubic.Checked == false) && (RBSine.Checked == false) && (RBCosine.Checked == false))
                {
                    //Messagebox is displayed
                    MessageBox.Show("Please specify a function to be displayed.", "Missing Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //If the "A" parameter is set to zero
                if ((int)NUDa.Value == 0)
                {
                    //Messagebox appears
                    MessageBox.Show("The A parameter set cannot equal to zero.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //If the "K" parameter is set to zero
                else if ((int)NUDk.Value == 0)
                {
                    //Messagebox appears
                    MessageBox.Show("The K parameter set cannot equal to zero.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //Color Dialog is displayed to user
                ColorDialog ClrDlg = new ColorDialog();

                if (ClrDlg.ShowDialog() == DialogResult.OK)
                {
                    //Color is set as BasicClr variable
                    c = ClrDlg.Color;
                }

                //if linear radio button is selected
                if (RBLinear.Checked == true)
                {
                    //Inputs are retrieved and set
                    myLinear.setXmax((int)NUDXmax.Value);
                    myLinear.setXmin((int)NUDXmin.Value);
                    myLinear.setYmax((int)NUDYmax.Value);
                    myLinear.setYmin((int)NUDYmin.Value);

                    myLinear.seta((int)NUDa.Value);
                    myLinear.setc((int)NUDc.Value);
                    myLinear.setd((int)NUDd.Value);
                    myLinear.setk((int)NUDk.Value);

                    myLinear.SetColor(c);
                    myLinear.Setscale();
                    myLinear.MakeTOV();
                    myLinear.TransformedTOV();
                    myLinear.transform();

                    PBFunction.Invalidate();

                    //Properties of function is stated
                    lblParentAnswer.Text = "f(x) = x";
                    lblDomainAnswer.Text = "{xE|R}";
                    lblRangeAnswer.Text  = "{yE|R}";
                }

                //if quadratic radiobutton is checked
                if (RBQuadratic.Checked == true)
                {
                    //myFunction.transform(myFunction.geta(),myFunction.getk(),myFunction.getd,myFunction.getc());
                    //Inputs are retrieved and set
                    myParabola.setXmax((int)NUDXmax.Value);
                    myParabola.setXmin((int)NUDXmin.Value);
                    myParabola.setYmax((int)NUDYmax.Value);
                    myParabola.setYmin((int)NUDYmin.Value);

                    myParabola.seta((int)NUDa.Value);
                    myParabola.setc((int)NUDc.Value);
                    myParabola.setd((int)NUDd.Value);
                    myParabola.setk((int)NUDk.Value);

                    myParabola.SetColor(c);
                    myParabola.Setscale();
                    myParabola.MakeTOV();
                    myParabola.TransformedTOV();
                    myParabola.transform();

                    PBFunction.Invalidate();

                    //Function properties
                    lblParentAnswer.Text = "f(x) = x^2";
                    lblDomainAnswer.Text = "{xE|R}";

                    if ((int)NUDa.Value < 0)
                    {
                        lblRangeAnswer.Text = "{yE|R| y<=" + (int)NUDc.Value + "}";
                    }

                    else if ((int)NUDa.Value > 0)
                    {
                        lblRangeAnswer.Text = "{yE|R| y>=" + (int)NUDc.Value + "}";
                    }
                }

                //if absolute radiobutton is checked
                if (RBAbsolute.Checked == true)
                {
                    //Inputs are retrieved and set
                    myAbsolute.setXmax((int)NUDXmax.Value);
                    myAbsolute.setXmin((int)NUDXmin.Value);
                    myAbsolute.setYmax((int)NUDYmax.Value);
                    myAbsolute.setYmin((int)NUDYmin.Value);

                    myAbsolute.seta((int)NUDa.Value);
                    myAbsolute.setc((int)NUDc.Value);
                    myAbsolute.setd((int)NUDd.Value);
                    myAbsolute.setk((int)NUDk.Value);

                    myAbsolute.SetColor(c);
                    myAbsolute.Setscale();
                    myAbsolute.MakeTOV();
                    myAbsolute.TransformedTOV();
                    myAbsolute.transform();
                    PBFunction.Invalidate();

                    //Function properties
                    lblParentAnswer.Text = "f(x) = |x|";
                    lblDomainAnswer.Text = "{xE|R}";

                    if ((int)NUDa.Value < 0)
                    {
                        lblRangeAnswer.Text = "{yE|R| y<=" + (int)NUDc.Value + "}";
                    }

                    else if ((int)NUDa.Value > 0)
                    {
                        lblRangeAnswer.Text = "{yE|R| y>=" + (int)NUDc.Value + "}";
                    }
                }

                //If root radio button is selected
                if (RBRoot.Checked == true)
                {
                    //Inputs are retrieved and set
                    myRoot.setXmax((int)NUDXmax.Value);
                    myRoot.setXmin((int)NUDXmin.Value);
                    myRoot.setYmax((int)NUDYmax.Value);
                    myRoot.setYmin((int)NUDYmin.Value);

                    myRoot.seta((int)NUDa.Value);
                    myRoot.setc((int)NUDc.Value);
                    myRoot.setd((int)NUDd.Value);
                    myRoot.setk((int)NUDk.Value);

                    myRoot.SetColor(c);
                    myRoot.Setscale();
                    myRoot.MakeTOV();
                    myRoot.TransformedTOV();
                    myRoot.transform();

                    PBFunction.Invalidate();

                    //Function properties
                    lblParentAnswer.Text = "f(x) = x^(1/2)";
                    if ((int)NUDk.Value < 0)
                    {
                        lblDomainAnswer.Text = "{xE|R| x<=" + (int)NUDd.Value + "}";
                    }

                    else if ((int)NUDk.Value > 0)
                    {
                        lblDomainAnswer.Text = "{xE|R| x>=" + (int)NUDd.Value + "}";
                    }

                    if ((int)NUDa.Value < 0)
                    {
                        lblRangeAnswer.Text = "{yE|R| y<=" + (int)NUDc.Value + "}";
                    }

                    else if ((int)NUDa.Value > 0)
                    {
                        lblRangeAnswer.Text = "{yE|R| y>=" + (int)NUDc.Value + "}";
                    }
                }


                //if cubic radiobutton  is checked
                if (RBCubic.Checked == true)
                {
                    //Inputs are retrieved and set
                    myCubic.setXmax((int)NUDXmax.Value);
                    myCubic.setXmin((int)NUDXmin.Value);
                    myCubic.setYmax((int)NUDYmax.Value);
                    myCubic.setYmin((int)NUDYmin.Value);

                    myCubic.seta((int)NUDa.Value);
                    myCubic.setc((int)NUDc.Value);
                    myCubic.setd((int)NUDd.Value);
                    myCubic.setk((int)NUDk.Value);

                    myCubic.SetColor(c);
                    myCubic.Setscale();
                    myCubic.MakeTOV();
                    myCubic.TransformedTOV();
                    myCubic.transform();

                    PBFunction.Invalidate();

                    //function properties
                    lblParentAnswer.Text = "f(x) = x^3";
                    lblDomainAnswer.Text = "{xE|R}";
                    lblRangeAnswer.Text  = "{yE|R}";
                }

                //if sine radio button is selected
                if (RBSine.Checked == true)
                {
                    //Inputs are retrieved and set
                    mySine.setXmax((int)NUDXmax.Value);
                    mySine.setXmin((int)NUDXmin.Value);
                    mySine.setYmax((int)NUDYmax.Value);
                    mySine.setYmin((int)NUDYmin.Value);

                    mySine.seta((int)NUDa.Value);
                    mySine.setc((int)NUDc.Value);
                    mySine.setd((int)NUDd.Value);
                    mySine.setk((int)NUDk.Value);

                    mySine.SetColor(c);
                    mySine.Setscale();
                    mySine.MakeTOV();
                    mySine.TransformedTOV();
                    mySine.transform();

                    PBFunction.Invalidate();

                    //Function properties
                    lblParentAnswer.Text = "f(x) = sin(x)";
                    lblDomainAnswer.Text = "{xE|R}";

                    if ((int)NUDa.Value > 0)
                    {
                        lblRangeAnswer.Text = "{yE|R| " + ((int)NUDa.Value + (int)NUDc.Value) + "<= y < =" + ((((int)NUDa.Value) * (-1)) + (int)NUDc.Value) + "}";
                    }

                    else if ((int)NUDa.Value < 0)
                    {
                        lblRangeAnswer.Text = "{yE|R| " + ((((int)NUDa.Value) * (-1)) + (int)NUDc.Value) + "<= y < =" + ((int)NUDa.Value + (int)NUDc.Value) + "}";
                    }
                }

                //if cosine radio button is selected
                if (RBCosine.Checked == true)
                {
                    //Inputs are retrieved and set
                    myCosine.setXmax((int)NUDXmax.Value);
                    myCosine.setXmin((int)NUDXmin.Value);
                    myCosine.setYmax((int)NUDYmax.Value);
                    myCosine.setYmin((int)NUDYmin.Value);

                    myCosine.seta((int)NUDa.Value);
                    myCosine.setc((int)NUDc.Value);
                    myCosine.setd((int)NUDd.Value);
                    myCosine.setk((int)NUDk.Value);

                    myCosine.SetColor(c);
                    myCosine.Setscale();
                    myCosine.MakeTOV();
                    myCosine.TransformedTOV();
                    myCosine.transform();

                    PBFunction.Invalidate();

                    //Function properties
                    lblParentAnswer.Text = "f(x) = cos(x)";
                    lblDomainAnswer.Text = "{xE|R}";

                    if ((int)NUDa.Value > 0)
                    {
                        lblRangeAnswer.Text = "{yE|R| " + ((int)NUDa.Value + (int)NUDc.Value) + "<= y < =" + ((((int)NUDa.Value) * (-1)) + (int)NUDc.Value) + "}";
                    }

                    else if ((int)NUDa.Value < 0)
                    {
                        lblRangeAnswer.Text = "{yE|R| " + ((((int)NUDa.Value) * (-1)) + (int)NUDc.Value) + "<= y < =" + ((int)NUDa.Value + (int)NUDc.Value) + "}";
                    }
                }
            }
            catch
            {
            }
        }