/* * 黄 * 蓝 红 * 绿 */ private void btnStart_Click(object sender, EventArgs e) { //pic是 PictureBox : Size=new Size(256, 256); Graphics g = pic.CreateGraphics(); g.Clear(Color.White); Pen blue = new Pen(Color.Blue); Pen red = new Pen(Color.Red); Pen yellow = new Pen(Color.Yellow); Pen green = new Pen(Color.Green); //绘制四角网线 int y = 255; int x = 0; for (x = 0; x < 256; x += 5) { ///每条线的两点沿着正方形的边顺时针走 g.DrawLine(yellow, x, 0, 255, x);///黄色第一点在正方形的顶边,第二点在正方形右边 g.DrawLine(red, 255, x, y, 255);//红色第一点在正方形的右边,第二点在正方形底边 g.DrawLine(green, y, 255, 0, y);//绿色第一点在正方形的底边,第二点在正方形左边 g.DrawLine(blue, 0, y, x, 0);//蓝色第一点在正方形的左边,第二点在正方形顶边 y -= 5; Thread.Sleep(50); } //四边透明度依次递减 for (y = 0; y < 256; y++) { using (Pen pen = new Pen(Color.FromArgb(y, Color.Yellow))) g.DrawLine(pen, 0, y, 255, y);//两点向下 y增大 using (Pen pen = new Pen(Color.FromArgb(y, Color.Red))) g.DrawLine(pen, x, 0, x, 255);//两点向左 x减小 using (Pen pen = new Pen(Color.FromArgb(y, Color.Green))) g.DrawLine(pen, 0, x, 255, x); using (Pen pen = new Pen(Color.FromArgb(y, Color.Blue))) g.DrawLine(pen, y, 0, y, 255); x--; if (y > 128) break; Thread.Sleep(10); } blue.Dispose(); red.Dispose(); green.Dispose(); yellow.Dispose(); }