예제 #1
0
        //shape without parameter.
        public Bitmap createShape(string type, Bitmap drawArea)
        {
            this.type = type;
            if (type == "circle")
            {
                shape shape = new Circle(drawArea);
                try
                {
                    drawArea = shape.draw();
                    return(drawArea);
                }
                catch (NotImplementedException e)
                {
                    MessageBox.Show(e.Message);
                };
            }
            else if (circleReg.IsMatch(type))
            {
                MessageBox.Show("hello");
                return(null);
            }
            else if (type == "rectangle")
            {
                graphicApplication.model.Rectangle shapeRec = new graphicApplication.model.Rectangle(drawArea);
                try
                {
                    drawArea = shapeRec.draw(400, 400);
                    return(drawArea);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
            else if (type == "drawLine")
            {
                line l = new line(drawArea);


                Pen p = new Pen(Color.Black, 2);
                drawArea = l.draw();

                return(drawArea);
            }
            else if (type == "triangle")
            {
                shape s = new Triangle(drawArea);
                drawArea = s.draw();
                return(drawArea);
            }
            else if (type == "polygon")
            {
                shape s = new Polygon(drawArea);
                drawArea = s.draw();
                return(drawArea);
            }


            return(null);
        }
예제 #2
0
        //shapes with normalParameter.
        public Bitmap createShape(string type, Bitmap drawArea, Dictionary <String, int> normalVarHolder)
        {
            String[] command   = type.Split('(', ',', ')');
            String   shapeType = command[0];

            this.normalVarHolder = normalVarHolder;
            //for circle
            if (shapeType.Equals("circle"))
            {
                Circle c       = new Circle(drawArea);
                String varName = command[1];
                // MessageBox.Show("" + varName);
                int radius = normalVarHolder[varName];
                drawArea = c.draw(radius);
                return(drawArea);
            }
            else if (shapeType.Equals("drawLine"))
            {
                //for line

                line   l          = new line(drawArea);
                String varXName   = command[1];
                String varYname   = command[2];
                int    xCordinate = normalVarHolder[varXName];
                int    yCordinate = normalVarHolder[varYname];
                drawArea = l.draw(xCordinate, yCordinate);
                return(drawArea);
            }
            else if (shapeType.Equals("rectangle"))
            {
                //for rectangle
                graphicApplication.model.Rectangle r = new graphicApplication.model.Rectangle(drawArea);
                String lname  = command[1];
                String hname  = command[2];
                int    length = normalVarHolder[lname];
                int    height = normalVarHolder[hname];

                drawArea = r.draw(length, height);
                return(drawArea);
            }



            return(null);
        }