Example #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     Pen p = new Pen(Color.Blue);
     PersonBuilder pb = new PersonThinBuilder(p, pictureBox1.CreateGraphics());
     PersonDirector pd = new PersonDirector(pb);
     pd.CreatePerson();
 }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Pen p = new Pen(Color.Yellow);
            PersonDirector pdThin = new PersonDirector("Thin",pictureBox1.CreateGraphics(),p);
            pdThin.CreatePerson();

            PersonDirector pdFat = new PersonDirector("Fat", pictureBox2.CreateGraphics(), p);
            pdFat.CreatePerson();
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            Pen p = new Pen(Color.Yellow);
            PersonThinBuilder ptb = new PersonThinBuilder(pictureBox1.CreateGraphics(), p);
            PersonDirector pdThin = new PersonDirector(ptb);
            pdThin.CreatePerson();

            PersonFatBuilder pfb = new PersonFatBuilder(pictureBox2.CreateGraphics(), p);
            PersonDirector pdFat = new PersonDirector(pfb);
            pdFat.CreatePerson();
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            Pen            p      = new Pen(Color.Yellow);
            PersonDirector pdThin = new PersonDirector("Thin", pictureBox1.CreateGraphics(), p);

            pdThin.CreatePerson();

            PersonDirector pdFat = new PersonDirector("Fat", pictureBox2.CreateGraphics(), p);

            pdFat.CreatePerson();
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            Pen p = new Pen(Color.Red);
            PersonThinBuilder ptb    = new PersonThinBuilder(pictureBox1.CreateGraphics(), p);
            PersonDirector    pdThin = new PersonDirector(ptb);

            pdThin.CreatePerson();

            PersonFatBuilder pfb   = new PersonFatBuilder(pictureBox2.CreateGraphics(), p);
            PersonDirector   pdFat = new PersonDirector(pfb);

            pdFat.CreatePerson();
        }
        public MainWindow()
        {
            InitializeComponent();

            #region 使用过程式创建
            //// 过程式绘制第一个小人
            //SolidColorBrush yellowBrush = new SolidColorBrush(Brushes.Yellow.Color);
            //double thickness = 5;
            ////DrawingEllipse(this.canvas, yellowBrush, thickness, new Point(65, 25), 20, 20);
            ////DrawingRectangle(this.canvas, yellowBrush, thickness, new Point(60, 50), 10, 50);
            ////DrawingLine1(this.canvas, yellowBrush, thickness, new Point(60, 50), new Point(40, 100));
            ////DrawingLine1(this.canvas, yellowBrush, thickness, new Point(70, 50), new Point(90, 100));
            ////DrawingLine2(this.canvas, yellowBrush, thickness, new Point(60, 100), new Point(45, 150), new Point(35, 150));
            ////DrawingLine2(this.canvas, yellowBrush, thickness, new Point(70, 100), new Point(85, 150), new Point(95, 150));

            //// 过程式绘制第二个小人
            //SolidColorBrush cyanBrush = new SolidColorBrush(Brushes.Cyan.Color);
            //DrawingEllipse(this.canvas, cyanBrush, thickness, new Point(65, 25), 20, 20);
            //DrawingRectangle(this.canvas, cyanBrush, thickness, new Point(45, 50), 40, 50);
            //DrawingLine1(this.canvas, cyanBrush, thickness, new Point(50, 50), new Point(30, 100));
            //DrawingLine1(this.canvas, cyanBrush, thickness, new Point(80, 50), new Point(100, 100));
            //DrawingLine2(this.canvas, cyanBrush, thickness, new Point(60, 100), new Point(45, 150), new Point(35, 150));
            //DrawingLine2(this.canvas, cyanBrush, thickness, new Point(70, 100), new Point(85, 150), new Point(95, 150));
            #endregion

            #region 使用面向对象方式创建
            //PersonThinBuilder thinBuilder = new PersonThinBuilder(this.canvas);
            //thinBuilder.Build();

            //PersonFatBuilder fatBuilder = new PersonFatBuilder(this.canvas);
            //fatBuilder.Build();
            #endregion

            #region 使用建造者模式创建
            SolidColorBrush    brush        = new SolidColorBrush(Brushes.Yellow.Color);
            double             thickness    = 5;
            PersonThinBuilderB thinBuilderB = new PersonThinBuilderB(this.canvas, brush, thickness);
            PersonDirector     thinPd       = new PersonDirector(thinBuilderB);
            thinPd.CreatePerson();

            brush     = new SolidColorBrush(Brushes.Cyan.Color);
            thickness = 5;
            PersonFatBuilderB fatBuilderB = new PersonFatBuilderB(this.canvas, brush, thickness);
            PersonDirector    fatPd       = new PersonDirector(fatBuilderB);
            fatPd.CreatePerson();
            #endregion
        }