using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace April25_2
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private int shapeType = 0; //0: rect, 1: ellipse, -1: clear
private int color = 0; //0: red, 1: green, 2: blue
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button buttonRed;
private System.Windows.Forms.Button buttonGreen;
private System.Windows.Forms.Button buttonBlue;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.buttonRed = new System.Windows.Forms.Button();
this.buttonGreen = new System.Windows.Forms.Button();
this.buttonBlue = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 160);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 32);
this.button1.TabIndex = 0;
this.button1.Text = "Rectangle";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(104, 160);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 32);
this.button2.TabIndex = 1;
this.button2.Text = "Ellipse";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(192, 160);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(64, 32);
this.button3.TabIndex = 2;
this.button3.Text = "Clear";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// buttonRed
//
this.buttonRed.BackColor = System.Drawing.Color.Tomato;
this.buttonRed.Location = new System.Drawing.Point(16, 216);
this.buttonRed.Name = "buttonRed";
this.buttonRed.Size = new System.Drawing.Size(56, 24);
this.buttonRed.TabIndex = 3;
this.buttonRed.Text = "Red";
this.buttonRed.Click += new System.EventHandler(this.buttonRed_Click);
//
// buttonGreen
//
this.buttonGreen.BackColor = System.Drawing.Color.LightGreen;
this.buttonGreen.Location = new System.Drawing.Point(112, 216);
this.buttonGreen.Name = "buttonGreen";
this.buttonGreen.Size = new System.Drawing.Size(56, 24);
this.buttonGreen.TabIndex = 4;
this.buttonGreen.Text = "Green";
this.buttonGreen.Click += new System.EventHandler(this.buttonGreen_Click);
//
// buttonBlue
//
this.buttonBlue.BackColor = System.Drawing.Color.LightBlue;
this.buttonBlue.Location = new System.Drawing.Point(200, 216);
this.buttonBlue.Name = "buttonBlue";
this.buttonBlue.Size = new System.Drawing.Size(56, 24);
this.buttonBlue.TabIndex = 5;
this.buttonBlue.Text = "Blue";
this.buttonBlue.Click += new System.EventHandler(this.buttonBlue_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(280, 260);
this.Controls.Add(this.buttonBlue);
this.Controls.Add(this.buttonGreen);
this.Controls.Add(this.buttonRed);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
shapeType = 0;
this.Invalidate();
}
private void button2_Click(object sender, System.EventArgs e)
{
shapeType = 1;
this.Invalidate();
}
private void button3_Click(object sender, System.EventArgs e)
{
shapeType = -1;
this.Invalidate();
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush b;
if(color==0)
b = Brushes.Tomato;
else if(color == 1)
b = Brushes.LightGreen;
else
b = b = Brushes.LightBlue;
if(shapeType==0)
{
g.FillRectangle(b,80,50,100,60);
}
else if (shapeType==1)
{
g.FillEllipse(b,80,50,100,60);
}
else
{
g.Clear(System.Drawing.SystemColors.Control);
}
}
private void buttonRed_Click(object sender, System.EventArgs e)
{
color = 0;
this.Invalidate();
}
private void buttonGreen_Click(object sender, System.EventArgs e)
{
color = 1;
this.Invalidate();
}
private void buttonBlue_Click(object sender, System.EventArgs e)
{
color = 2;
this.Invalidate();
}
}
}