示例#1
0
        private void btnDraw_Click(object sender, EventArgs e)
        {
            int selectedIndex = cbbShape.SelectedIndex;

            if (selectedIndex < 0)
            {
                return;
            }

            switch (selectedIndex)
            {
            case 0:
                _graphics.Clear(Color.White);
                _shape = new Circle(_drawing,
                                    new PointF(
                                        _ucCircleInfo.CircleX,
                                        _ucCircleInfo.CircleY),
                                    _ucCircleInfo.CircleRadius, pnlColor.BackColor);
                _shape.Draw(_graphics);
                break;

            case 1:
                _graphics.Clear(Color.White);
                _shape = new ConcreteAbstractions.Rectangle(_drawing,
                                                            new PointF(_ucRectangleInfo.RectX, _ucRectangleInfo.RectY),
                                                            new SizeF(_ucRectangleInfo.RectWidth, _ucRectangleInfo.RectHeight),
                                                            pnlColor.BackColor);
                _shape.Draw(_graphics);
                break;

            default: break;
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Shape s = new Shape();

            s.Draw();
            Rectangle r = new Rectangle();

            r.Draw();

            //OO Rule - Base Class ref variable can hold derived class object

            Shape shapeRef = new Rectangle();

            shapeRef.Draw();                    //Late Binding

            //All methods in a class are default non-virtual
        }
示例#3
0
        public static void DrawShapes()
        {
            Shape shape = null;

            do
            {
                Console.Clear();
                Console.WriteLine("[1] Triangle");
                Console.WriteLine("[2] Circle");
                Console.WriteLine("[3] Rectange");
                Console.WriteLine("[4] All");

                ConsoleKey input = Console.ReadKey().Key;

                switch (input)
                {
                case ConsoleKey.D1:
                    shape = new Triangle();
                    break;

                case ConsoleKey.D2:
                    shape = new Circle();
                    break;

                case ConsoleKey.D3:
                    shape = new Rectangle();
                    break;

                case ConsoleKey.D4:
                    shape = new Shape();
                    break;
                }

                shape?.Draw();
            }while (Console.ReadKey().Key != ConsoleKey.Spacebar);
        }