Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
C#
public abstract class Shape
    {
        //Fields
        private const int BORDER_WIDTH = 5;
        private bool _showBorder = true;
        private Color _color;
        private Point _location;
        public Control _BaseCanvas;
        private bool _isSelected;
        

        //Properties
        public bool IsSelected
        {
            get { return _isSelected; }
            set { _isSelected = value; }
        }
        public float BorderWidth
        {
            get { return BORDER_WIDTH; }
        }
        public bool ShowBorder
        {
            get { return _showBorder; }
            set { _showBorder = value; }
        }
        public Color Color
        {
            get { return _color; }
            set { _color = value; }
        }
        public int Xposition
        {
            get { return _location.X; }
            set { _location.X = value; }
        }
        public int Yposition
        {
            get { return _location.Y; }
            set { _location.Y = value; }
        }
        public Point Location
        {
            get { return _location; }
            set { _location = value; }
        }

        public static Shape self;

        /// <summary>
        /// Default Constructor 
        /// </summary>
        public Shape(Control refCanvas)
        {
            _BaseCanvas = refCanvas;
            _color = Color.Black;
            self = this;
        }

        /// <summary>
        /// Constructor with Position
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public Shape(Control refCanvas, Point location) : this(refCanvas)
        {
            _location = location;
        }

        public abstract void Draw();
       // public abstract void Paint();
    }

//Inherits form Base Class Shape
    class Square : Shape
    {
        // Protected field members
        protected int _size;

        //Public Properties
        public int Size
        {
            get { return _size; }
            set { _size = value; }
        }

        /// <summary>
        /// Constructor with base form initialization
        /// </summary>
        /// <param name="ContainerForm"></param>
        public Square(Control objControl) : base(objControl) { }
        public Square(Control objControl, Point location) : base(objControl, location) { }

        /// <summary>
        /// Function to draw Square
        /// </summary>
        public override void Draw()
        {
            Graphics g = _BaseCanvas.CreateGraphics();
            Pen p = new Pen(Color);
            p.Width = BorderWidth;
            g.DrawRectangle(p, Xposition, Yposition, _size, _size);
        }

    }
Posted
Updated 10-Jun-15 5:26am
v2
Comments
Sergey Alexandrovich Kryukov 10-Jun-15 12:14pm    
Why creating anything Paint-like? One bad application already exist, why creating another bad one? Better created something Inkscape-based, as Canvas is the closest to it. But this good application already exist. So, if you have some different or additional idea, it may make sense.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900