using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Radio_Check
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{

Color colorRect = Color.Black;
bool bFill = false;

private System.Windows.Forms.CheckBox checkBoxFill;
private System.Windows.Forms.GroupBox groupBoxColor;
private System.Windows.Forms.RadioButton radioButtonRed;
private System.Windows.Forms.RadioButton radioButtonGreen;
private System.Windows.Forms.RadioButton radioButtonBlue;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.checkBoxFill = new System.Windows.Forms.CheckBox();
this.groupBoxColor = new System.Windows.Forms.GroupBox();
this.radioButtonRed = new System.Windows.Forms.RadioButton();
this.radioButtonGreen = new System.Windows.Forms.RadioButton();
this.radioButtonBlue = new System.Windows.Forms.RadioButton();
this.groupBoxColor.SuspendLayout();
this.SuspendLayout();
//
// checkBoxFill
//
this.checkBoxFill.Location = new System.Drawing.Point(48, 248);
this.checkBoxFill.Name = "checkBoxFill";
this.checkBoxFill.TabIndex = 0;
this.checkBoxFill.Text = "Fill Rectangle";
this.checkBoxFill.CheckedChanged += new System.EventHandler(this.checkBoxFill_CheckedChanged);
//
// groupBoxColor
//
this.groupBoxColor.Controls.AddRange(new System.Windows.Forms.Control[] {
this.radioButtonBlue,
this.radioButtonGreen,
this.radioButtonRed});
this.groupBoxColor.Location = new System.Drawing.Point(32, 32);
this.groupBoxColor.Name = "groupBoxColor";
this.groupBoxColor.Size = new System.Drawing.Size(144, 176);
this.groupBoxColor.TabIndex = 1;
this.groupBoxColor.TabStop = false;
this.groupBoxColor.Text = "Color Selection";
//
// radioButtonRed
//
this.radioButtonRed.Location = new System.Drawing.Point(16, 40);
this.radioButtonRed.Name = "radioButtonRed";
this.radioButtonRed.TabIndex = 0;
this.radioButtonRed.Text = "Red";
this.radioButtonRed.CheckedChanged += new System.EventHandler(this.radioButtonRed_CheckedChanged);
//
// radioButtonGreen
//
this.radioButtonGreen.Location = new System.Drawing.Point(16, 80);
this.radioButtonGreen.Name = "radioButtonGreen";
this.radioButtonGreen.TabIndex = 1;
this.radioButtonGreen.Text = "Green";
this.radioButtonGreen.CheckedChanged += new System.EventHandler(this.radioButtonGreen_CheckedChanged);
//
// radioButtonBlue
//
this.radioButtonBlue.Location = new System.Drawing.Point(16, 120);
this.radioButtonBlue.Name = "radioButtonBlue";
this.radioButtonBlue.TabIndex = 2;
this.radioButtonBlue.Text = "Blue";
this.radioButtonBlue.CheckedChanged += new System.EventHandler(this.radioButtonBlue_CheckedChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(400, 341);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBoxColor,
this.checkBoxFill});
this.Name = "Form1";
this.Text = "Radio Buttons and Check Boxe";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.groupBoxColor.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void checkBoxFill_CheckedChanged(object sender, System.EventArgs e)
{
bFill = ((CheckBox)sender).Checked;
Invalidate();
}

private void radioButtonRed_CheckedChanged(object sender, System.EventArgs e)
{
colorRect = Color.Red;
Invalidate();
}

private void radioButtonGreen_CheckedChanged(object sender, System.EventArgs e)
{
colorRect = Color.Green;
Invalidate();
}

private void radioButtonBlue_CheckedChanged(object sender, System.EventArgs e)
{
colorRect = Color.Blue;
Invalidate();
}

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
int w = this.ClientRectangle.Width;
int h = this.ClientRectangle.Height;
Graphics g = e.Graphics;
if (bFill)
{
Brush b = new SolidBrush(colorRect);
g.FillRectangle(b, w/2, 10, w/2-20, h-20);
}
else
{
Pen p = new Pen(colorRect,3);
g.DrawRectangle(p, w/2, 10, w/2-20, h-20);
}
}
}
}