using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Example73
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox2;
///
/// 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.textBox1 = new System.Windows.Forms.TextBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(64, 120);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(64, 20);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "0";
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"eggs",
"milk",
"bread"});
this.comboBox1.Location = new System.Drawing.Point(64, 80);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(88, 21);
this.comboBox1.TabIndex = 3;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(72, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(160, 32);
this.label1.TabIndex = 4;
this.label1.Text = "Edit your cart";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// button1
//
this.button1.Location = new System.Drawing.Point(176, 120);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 5;
this.button1.Text = "Order";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 176);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(168, 88);
this.label2.TabIndex = 6;
this.label2.Text = "Your have purchaged";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 80);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 24);
this.label3.TabIndex = 7;
this.label3.Text = "Items";
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 120);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(48, 24);
this.label4.TabIndex = 8;
this.label4.Text = "Quantity";
//
// label5
//
this.label5.Location = new System.Drawing.Point(176, 80);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(96, 24);
this.label5.TabIndex = 9;
this.label5.Text = "Price: ";
//
// button2
//
this.button2.Location = new System.Drawing.Point(208, 240);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 24);
this.button2.TabIndex = 10;
this.button2.Text = "Total";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(280, 240);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(48, 20);
this.textBox2.TabIndex = 11;
this.textBox2.Text = "$ 0.00";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(352, 308);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button2);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//textBox1.Text = lstShopping.SelectedIndex.ToString();
//textBox1.Text = lstShopping.SelectedItem.ToString();
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//textBox1.Text = comboBox1.SelectedItem.ToString();
int s = comboBox1.SelectedIndex;
if(s==0)
label5.Text = "$1.90 per dozen";
if(s==1)
label5.Text = "$1.47 per quart";
if(s==2)
label5.Text = "$2.12 per loaf";
}
int num_egg = 0;
int num_bread = 0;
int num_milk = 0;
private void button1_Click(object sender, System.EventArgs e)
{
int quantity = int.Parse(textBox1.Text.ToString());
double total = 0.0;
int item = comboBox1.SelectedIndex;
if(item==0)
{
num_egg = quantity;
}
else if(item==1)
{
num_milk = quantity;
}
else
{
num_bread = quantity;
}
string description = "You have purchased\n" +
num_egg + " dozen(s) of eggs\n"+
num_milk + " quart(s) of milk\n"+
num_bread + " loaf(s) of bread";
label2.Text = description;
}
private void button2_Click(object sender, System.EventArgs e)
{
double total = num_egg * 1.9 + num_bread * 2.12 + num_milk * 1.47;
textBox2.Text = string.Format("{0:C2}",total);
}
}
}