コード例 #1
0
        private void ComputeButton_Click(object sender, EventArgs e)
        {
            int width  = Convert.ToInt32(width_NumericUpDown.Value);
            int height = Convert.ToInt32(height_NumericUpDown.Value);

            RectangleLibrary.Rectangle rect = new RectangleLibrary.Rectangle()
            {
                Width = width, Height = height
            };
            RectangleOperation operation = new RectangleOperation();

            operation.Target = rect;
            int area = operation.ComputeArea();

            resultLabel.Text = $"長方形的面積為 {area}";
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int width = 0;

            Int32.TryParse(numericUpDown1.Value.ToString(), out width);
            var height = (int)numericUpDown2.Value;

            RectangleLibrary.Rectangle rect = new RectangleLibrary.Rectangle()
            {
                Width = width, Height = height
            };
            RectangleOperation operation = new RectangleOperation();

            operation.Target = rect;
            int area = operation.ComputeArea();

            label3.Text = area.ToString();
        }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            Shape[] shapes = new Shape[20];
            Random  random = new Random();

            for (int i = 0; i < shapes.Length; i++)
            {
                if (random.Next(0, 5) == 0)
                {
                    shapes[i] = new PointLibrary.Point();
                }

                else if (random.Next(0, 5) == 1)
                {
                    shapes[i] = new Line();
                }

                else if (random.Next(0, 5) == 2)
                {
                    shapes[i] = new RectangleLibrary.Rectangle();
                }

                else if (random.Next(0, 5) == 3)
                {
                    shapes[i] = new Circle();
                }

                else if (random.Next(0, 5) == 4)
                {
                    shapes[i] = new Ellipse();
                }
            }

            for (int i = 0; i < shapes.Length; i++)
            {
                shapes[i].Draw(pictureBoxShapes.CreateGraphics());
            }
        }