using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
private string strColor;
public static void Main() {
Application.Run(new Form1());
}
private void Form1_Click(object sender, EventArgs e) {
switch (strColor) {
case "red":
strColor = "yellow";
break;
case "yellow":
strColor = "green";
break;
default:
strColor = "red";
break;
}
this.Invalidate(new Rectangle(10, 10, 50, 150));
}
private void Form1_Paint(object sender, PaintEventArgs e) {
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
g.FillRectangle(Brushes.Black, 10, 10, 50, 150);
g.DrawEllipse(Pens.White, 15, 15, 40, 40);
g.DrawEllipse(Pens.White, 15, 60, 40, 40);
g.DrawEllipse(Pens.White, 15, 105, 40, 40);
switch (strColor) {
case "red":
g.FillEllipse(Brushes.Red, 15, 15, 40, 40);
break;
case "yellow":
g.FillEllipse(Brushes.Yellow, 15, 60, 40, 40);
break;
case "green":
g.FillEllipse(Brushes.Green, 15, 105, 40, 40);
break;
default:
g.FillEllipse(Brushes.Red, 15, 15, 40, 40);
break;
}
}
}
|