呵呵,第一次玩,总是有点兴趣。慢慢摸索坐标系的定位。
连代码放在哪里都不知道,书上也没有说,以为高手都懂的。
我试了三四个位置才了解。MAINFORM.CS里,用BUTTON激活之~~
将两个小人画在同一个PICTUREBOX上啦。
这是为了理解后面的建造者模式作的比较代码。勿模仿~~
关键代码:
1 2 void Button1Click(object sender, EventArgs e) 3 { 4 Graphics gThin = this.pictureBox1.CreateGraphics(); 5 Pen pen = new Pen(Color.Pink); 6 gThin.DrawEllipse(pen, 50, 20, 30, 30); 7 gThin.DrawRectangle(pen, 60, 50, 10, 50); 8 gThin.DrawLine(pen, 60, 50, 40, 100); 9 gThin.DrawLine(pen, 70, 50, 90, 100);10 gThin.DrawLine(pen, 60, 100, 45, 150);11 gThin.DrawLine(pen, 70, 100, 85, 150);12 }13 void Button2Click(object sender, System.EventArgs e)14 {15 Graphics gFat = pictureBox1.CreateGraphics();16 Pen penFat = new Pen(Color.Red);17 gFat.DrawEllipse(penFat, 150, 20, 30, 30);18 gFat.DrawEllipse(penFat, 145, 50, 40, 50);19 gFat.DrawLine(penFat, 150, 50, 130, 100);20 gFat.DrawLine(penFat, 180, 50, 200, 100);21 gFat.DrawLine(penFat, 160, 100, 145, 150);22 gFat.DrawLine(penFat, 170, 100, 185, 150);23 24 }
嘿嘿,,输出像不像瘦人和胖人??