Пример #1
0
        private void pnlCanvas_MouseClick(object sender, MouseEventArgs e)
        {
            Shape drawingShape = null;

            switch (cmbShapes.Text.Trim())
            {
            case "Circle":
                if (txtRadius.Text == string.Empty)
                {
                    MessageBox.Show("Please input radius");
                }
                else
                {
                    drawingShape = new Circle(e.X, e.Y, Convert.ToDouble(txtRadius.Text), ShapesBorderColour);
                    //drawingShape.BorderColor = "Black"; <--- can also pass colour like this
                }

                break;

            case "Square":
                if (txtLength.Text == string.Empty)
                {
                    MessageBox.Show("Please input length");
                }
                else
                {
                    drawingShape = new Square(e.X, e.Y, Convert.ToDouble(txtLength.Text));
                }
                break;

            case "Rectangle":
                if (txtLength.Text == string.Empty || txtWidth.Text == string.Empty)
                {
                    MessageBox.Show("Please input length");
                }
                else
                {
                    drawingShape = new ShapesLibrary.Rectangle(e.X, e.Y, Convert.ToDouble(txtLength.Text), Convert.ToDouble(txtWidth.Text));
                }
                break;

            default:
                break;
            }

            if (drawingShape != null)
            {
                drawingShape.Draw(pnlCanvas.CreateGraphics());
            }
        }
Пример #2
0
        //Purpose: To Process Information when Enter has been clicked
        //Requires: The user to click enter and the shape previously entered
        //Returns: none
        private void Enter_Click(object sender, EventArgs e)
        {
            try {
                // get the coordinates for the first point
                firstX = Double.Parse(pointBox1.Text);
                firstY = Double.Parse(pointBox2.Text);

                switch (shapeName)
                {
                case "circle":
                {
                    enteredRadius = Double.Parse(pointBox3.Text);
                    Circle circle = new Circle(enteredRadius, firstX, firstY, 0, shapeName);
                    // use ToString to output to the output boxes
                    OutputLabel1.Text = circle.ToString();
                    // show the associated picture
                    displayPicture(shapeName);
                }
                break;

                case "square":

                    secX = Double.Parse(pointBox3.Text);
                    Square square = new Square(firstX, firstY, secX, shapeName);
                    // use ToString to output to the output boxes
                    OutputLabel1.Text = square.ToString();
                    // show the associated picture
                    displayPicture(shapeName);
                    break;

                case "rectangle":
                    secX = Double.Parse(pointBox3.Text);
                    secY = Double.Parse(pointBox4.Text);
                    ShapesLibrary.Rectangle rectangle = new ShapesLibrary.Rectangle(firstX, firstY, secX, secY, shapeName);
                    // use ToString to output to the output boxes
                    OutputLabel1.Text = rectangle.ToString();
                    // show the associated picture
                    displayPicture(shapeName);
                    break;

                case "cube":
                    secX = Double.Parse(pointBox3.Text);
                    Cube cube = new Cube(firstX, firstY, secX, shapeName);
                    // use ToString to output to the output boxes
                    OutputLabel1.Text = cube.ToString();
                    // show the associated picture
                    displayPicture(shapeName);
                    break;

                case "cylinder":
                    enteredRadius = Double.Parse(pointBox3.Text);
                    height        = Double.Parse(pointBox4.Text);
                    Cylinder cylinder = new Cylinder(enteredRadius, firstX, firstY, height, shapeName);
                    // use ToString to output to the output boxes
                    OutputLabel1.Text = cylinder.ToString();
                    // show the associated picture
                    displayPicture(shapeName);
                    break;

                case "sphere":
                    enteredRadius = Double.Parse(pointBox3.Text);
                    Sphere sphere = new Sphere(enteredRadius, firstX, firstY, 0, shapeName);
                    // use ToString to output to the output boxes
                    OutputLabel1.Text = sphere.ToString();
                    // show the associated picture
                    displayPicture(shapeName);
                    break;

                case "cuboid":
                    enteredWidth = Double.Parse(pointBox3.Text);
                    height       = Double.Parse(pointBox4.Text);
                    Cuboid cuboid = new Cuboid(firstX, firstY, enteredWidth, height, shapeName);
                    // use ToString to output to the output boxes
                    OutputLabel1.Text = cuboid.ToString();
                    // show the associated picture
                    displayPicture(shapeName);
                    break;

                default:
                    OutputLabel1.Visible = true;
                    OutputLabel1.Text    = String.Format("Invalid Choice!");
                    break;
                }
            }
            catch (NegativeNumberException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (FormatException f)
            {
                MessageBox.Show(" Please fill in all the information needed.");
            }
            pointBox1.Clear();
            pointBox2.Clear();
            pointBox3.Clear();
            pointBox4.Clear();
        }