using System;
using System.Drawing;
using System.Windows.Forms;
using Indyjug;
namespace Indyjug {
///
/// Summary description for ShapeGUI.
///
public class ShapeGUI : Form {
private Label radiusLbl;
private TextBox radiusTxt;
private Label perimeterLbl;
private Label perimeterValueLbl;
private Label areaLbl;
private Label areaValueLbl;
private Button computePerimeterAreaBtn;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public ShapeGUI() {
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
///
/// 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.radiusLbl = new Label();
this.radiusTxt = new TextBox();
this.perimeterLbl = new Label();
this.perimeterValueLbl = new Label();
this.areaLbl = new Label();
this.areaValueLbl = new Label();
this.computePerimeterAreaBtn = new Button();
this.SuspendLayout();
//
// radiusLbl
//
this.radiusLbl.Location = new Point(25, 25);
this.radiusLbl.Name = "radiusLbl";
this.radiusLbl.Size = new Size(56, 23);
this.radiusLbl.TabIndex = 1;
this.radiusLbl.Text = "Radius:";
this.radiusLbl.TextAlign = ContentAlignment.MiddleLeft;
//
// radiusTxt
//
this.radiusTxt.Location = new Point(100, 25);
this.radiusTxt.Name = "radiusTxt";
this.radiusTxt.Size = new Size(150, 23);
this.radiusTxt.TabIndex = 2;
this.radiusTxt.Text = "";
this.radiusTxt.TextAlign = HorizontalAlignment.Left;
//
// perimeterLbl
//
this.perimeterLbl.Location = new Point(25, 50);
this.perimeterLbl.Name = "perimeterLbl";
this.perimeterLbl.Size = new Size(56, 23);
this.perimeterLbl.TabIndex = 3;
this.perimeterLbl.Text = "Perimeter:";
this.perimeterLbl.TextAlign = ContentAlignment.MiddleLeft;
//
// perimeterValueLbl
//
this.perimeterValueLbl.Location = new Point(100, 50);
this.perimeterValueLbl.Name = "perimeterValueLbl";
this.perimeterValueLbl.Size = new Size(150, 23);
this.perimeterValueLbl.TabIndex = 4;
this.perimeterValueLbl.Text = "";
this.perimeterValueLbl.TextAlign = ContentAlignment.MiddleLeft;
//
// areaLbl
//
this.areaLbl.Location = new Point(25, 75);
this.areaLbl.Name = "areaLbl";
this.areaLbl.Size = new Size(56, 23);
this.areaLbl.TabIndex = 5;
this.areaLbl.Text = "Area:";
this.areaLbl.TextAlign = ContentAlignment.MiddleLeft;
//
// areaValueLbl
//
this.areaValueLbl.Location = new Point(100, 75);
this.areaValueLbl.Name = "areaValueLbl";
this.areaValueLbl.Size = new Size(150, 23);
this.areaValueLbl.TabIndex = 6;
this.areaValueLbl.Text = "";
this.areaValueLbl.TextAlign = ContentAlignment.MiddleLeft;
//
// computePerimeterAreaBtn
//
this.computePerimeterAreaBtn.Location = new Point(75, 100);
this.computePerimeterAreaBtn.Name = "computePerimeterAreaBtn";
this.computePerimeterAreaBtn.Size = new Size(150, 23);
this.computePerimeterAreaBtn.TabIndex = 7;
this.computePerimeterAreaBtn.Text = "Compute Perimeter && Area";
this.computePerimeterAreaBtn.TextAlign = ContentAlignment.MiddleRight;
this.computePerimeterAreaBtn.Click += new EventHandler(this.computePerimeterAreaBtn_Click);
//
// ShapeGUI
//
this.AutoScaleBaseSize = new Size(5, 13);
this.ClientSize = new Size(275, 150);
this.Controls.AddRange(new Control[] {
this.radiusLbl,
this.radiusTxt,
this.perimeterLbl,
this.perimeterValueLbl,
this.areaLbl,
this.areaValueLbl,
this.computePerimeterAreaBtn});
this.Name = "ShapeGUI";
this.Text = "ShapeGUI";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
// The STAThread attribute informs the common language runtime that
// Windows Forms uses the single-threaded apartment model.
[STAThread]
static void Main() {
Application.Run(new ShapeGUI());
}
private void computePerimeterAreaBtn_Click(object sender, EventArgs e) {
try {
double radius = Double.Parse(radiusTxt.Text);
Circle circle = new Circle(radius);
perimeterValueLbl.Text = Convert.ToString(circle.ComputePerimeter());
areaValueLbl.Text = Convert.ToString(circle.ComputeArea());
}
catch (FormatException ex) {
MessageBox.Show("Please enter a numeric value", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
radiusTxt.Text = "";
perimeterValueLbl.Text = "";
areaValueLbl.Text = "";
radiusTxt.Focus();
}
}
}
}