1 Textbox
3 Radio buttons
2 buttons
6 Labels
1 List box
2 panels
5 Checkboxes
Code must be written to respond to the user clicking on the buttons, radio buttons and check boxes.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
public enum Flavor
{
Chocolate = 5,
Vanilla = 5,
Pistachio = 10,
Berry = 10,
Orange = 15,
}
public enum Topping
{
Biscuit = 10,
Candies = 15,
Syrup = 20
}
namespace WindowfFormsTask
{
public partial class MainForm : Form
{
int check = 0;
public MainForm()
{
InitializeComponent();
ScoopsComboBox.Items.AddRange(new object[] { "1", "2", "3" });
ScoopsComboBox.SelectedItem = 0;
CheckTextBox.Text = $"{0:C}";
}
private void ExitButton_Click(object sender, EventArgs e)
{
Close();
}
private void AddButton_Click(object sender, EventArgs e)
{
List<Flavor> flavors = new List<Flavor>();
Topping topping = new Topping();
foreach (CheckBox item in Controls.OfType<CheckBox>())
{
if (item.Checked)
{
Enum.TryParse<Flavor>(item.Text, true, out Flavor type);
flavors.Add(type);
}
}
foreach (RadioButton item in Controls.OfType<RadioButton>())
{
if (item.Checked)
{
Enum.TryParse<Topping>(item.Text, true, out Topping type);
topping = type;
}
}
int numberOfScoops = int.Parse(ScoopsComboBox.SelectedItem.ToString());
check = numberOfScoops * 5 + flavors.Sum(x => (int)x)+ (int)topping;
CheckTextBox.Text = $"{check:C}";
}
private void ClearButton_Click(object sender, EventArgs e)
{
CheckTextBox.Text = $"{0:C}";
}
}
}
namespace WindowfFormsTask
{
partial class MainForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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.CheckTextBox = new System.Windows.Forms.TextBox();
this.AddButton = new System.Windows.Forms.Button();
this.ScoopsComboBox = new System.Windows.Forms.ComboBox();
this.ClearButton = new System.Windows.Forms.Button();
this.ExitButton = new System.Windows.Forms.Button();
this.CheckLabel = new System.Windows.Forms.Label();
this.FlavorLabel = new System.Windows.Forms.Label();
this.ScoopLabel = new System.Windows.Forms.Label();
this.ChocolateCheckBox = new System.Windows.Forms.CheckBox();
this.BiscuitRadioButton = new System.Windows.Forms.RadioButton();
this.VanillaCheckBox = new System.Windows.Forms.CheckBox();
this.PistachioCheckBox = new System.Windows.Forms.CheckBox();
this.BerryCheckBox = new System.Windows.Forms.CheckBox();
this.OrangeCheckBox = new System.Windows.Forms.CheckBox();
this.CandiesRadioButton = new System.Windows.Forms.RadioButton();
this.SyrupRadioButton = new System.Windows.Forms.RadioButton();
this.ToppingLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// CheckTextBox
//
this.CheckTextBox.Location = new System.Drawing.Point(26, 134);
this.CheckTextBox.Name = "CheckTextBox";
this.CheckTextBox.ReadOnly = true;
this.CheckTextBox.Size = new System.Drawing.Size(105, 20);
this.CheckTextBox.TabIndex = 0;
//
// AddButton
//
this.AddButton.Location = new System.Drawing.Point(307, 217);
this.AddButton.Name = "AddButton";
this.AddButton.Size = new System.Drawing.Size(155, 23);
this.AddButton.TabIndex = 1;
this.AddButton.Text = "Add...";
this.AddButton.UseVisualStyleBackColor = true;
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
//
// ScoopsComboBox
//
this.ScoopsComboBox.FormattingEnabled = true;
this.ScoopsComboBox.Location = new System.Drawing.Point(206, 83);
this.ScoopsComboBox.Name = "ScoopsComboBox";
this.ScoopsComboBox.Size = new System.Drawing.Size(93, 21);
this.ScoopsComboBox.TabIndex = 2;
//
// ClearButton
//
this.ClearButton.Location = new System.Drawing.Point(26, 217);
this.ClearButton.Name = "ClearButton";
this.ClearButton.Size = new System.Drawing.Size(105, 23);
this.ClearButton.TabIndex = 3;
this.ClearButton.Text = "Clear";
this.ClearButton.UseVisualStyleBackColor = true;
this.ClearButton.Click += new System.EventHandler(this.ClearButton_Click);
//
// ExitButton
//
this.ExitButton.Location = new System.Drawing.Point(307, 289);
this.ExitButton.Name = "ExitButton";
this.ExitButton.Size = new System.Drawing.Size(155, 23);
this.ExitButton.TabIndex = 4;
this.ExitButton.Text = "Exit";
this.ExitButton.UseVisualStyleBackColor = true;
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);
//
// CheckLabel
//
this.CheckLabel.AutoSize = true;
this.CheckLabel.Location = new System.Drawing.Point(33, 52);
this.CheckLabel.Name = "CheckLabel";
this.CheckLabel.Size = new System.Drawing.Size(41, 13);
this.CheckLabel.TabIndex = 6;
this.CheckLabel.Text = "Check:";
//
// FlavorLabel
//
this.FlavorLabel.AutoSize = true;
this.FlavorLabel.Location = new System.Drawing.Point(325, 52);
this.FlavorLabel.Name = "FlavorLabel";
this.FlavorLabel.Size = new System.Drawing.Size(42, 13);
this.FlavorLabel.TabIndex = 7;
this.FlavorLabel.Text = "Flavor :";
//
// ScoopLabel
//
this.ScoopLabel.AutoSize = true;
this.ScoopLabel.Location = new System.Drawing.Point(203, 52);
this.ScoopLabel.Name = "ScoopLabel";
this.ScoopLabel.Size = new System.Drawing.Size(96, 13);
this.ScoopLabel.TabIndex = 8;
this.ScoopLabel.Text = "Number of scoops:";
//
// ChocolateCheckBox
//
this.ChocolateCheckBox.AutoSize = true;
this.ChocolateCheckBox.Location = new System.Drawing.Point(328, 88);
this.ChocolateCheckBox.Name = "ChocolateCheckBox";
this.ChocolateCheckBox.Size = new System.Drawing.Size(74, 17);
this.ChocolateCheckBox.TabIndex = 9;
this.ChocolateCheckBox.Text = "Chocolate";
this.ChocolateCheckBox.UseVisualStyleBackColor = true;
//
// BiscuitRadioButton
//
this.BiscuitRadioButton.AutoSize = true;
this.BiscuitRadioButton.Location = new System.Drawing.Point(443, 87);
this.BiscuitRadioButton.Name = "BiscuitRadioButton";
this.BiscuitRadioButton.Size = new System.Drawing.Size(56, 17);
this.BiscuitRadioButton.TabIndex = 10;
this.BiscuitRadioButton.TabStop = true;
this.BiscuitRadioButton.Text = "Biscuit";
this.BiscuitRadioButton.UseVisualStyleBackColor = true;
//
// VanillaCheckBox
//
this.VanillaCheckBox.AutoSize = true;
this.VanillaCheckBox.Location = new System.Drawing.Point(328, 111);
this.VanillaCheckBox.Name = "VanillaCheckBox";
this.VanillaCheckBox.Size = new System.Drawing.Size(57, 17);
this.VanillaCheckBox.TabIndex = 11;
this.VanillaCheckBox.Text = "Vanilla";
this.VanillaCheckBox.UseVisualStyleBackColor = true;
//
// PistachioCheckBox
//
this.PistachioCheckBox.AutoSize = true;
this.PistachioCheckBox.Location = new System.Drawing.Point(328, 134);
this.PistachioCheckBox.Name = "PistachioCheckBox";
this.PistachioCheckBox.Size = new System.Drawing.Size(69, 17);
this.PistachioCheckBox.TabIndex = 12;
this.PistachioCheckBox.Text = "Pistachio";
this.PistachioCheckBox.UseVisualStyleBackColor = true;
//
// BerryCheckBox
//
this.BerryCheckBox.AutoSize = true;
this.BerryCheckBox.Location = new System.Drawing.Point(328, 157);
this.BerryCheckBox.Name = "BerryCheckBox";
this.BerryCheckBox.Size = new System.Drawing.Size(50, 17);
this.BerryCheckBox.TabIndex = 13;
this.BerryCheckBox.Text = "Berry";
this.BerryCheckBox.UseVisualStyleBackColor = true;
//
// OrangeCheckBox
//
this.OrangeCheckBox.AutoSize = true;
this.OrangeCheckBox.Location = new System.Drawing.Point(328, 178);
this.OrangeCheckBox.Name = "OrangeCheckBox";
this.OrangeCheckBox.Size = new System.Drawing.Size(61, 17);
this.OrangeCheckBox.TabIndex = 14;
this.OrangeCheckBox.Text = "Orange";
this.OrangeCheckBox.UseVisualStyleBackColor = true;
//
// CandiesRadioButton
//
this.CandiesRadioButton.AutoSize = true;
this.CandiesRadioButton.Location = new System.Drawing.Point(443, 133);
this.CandiesRadioButton.Name = "CandiesRadioButton";
this.CandiesRadioButton.Size = new System.Drawing.Size(63, 17);
this.CandiesRadioButton.TabIndex = 15;
this.CandiesRadioButton.TabStop = true;
this.CandiesRadioButton.Text = "Candies";
this.CandiesRadioButton.UseVisualStyleBackColor = true;
//
// SyrupRadioButton
//
this.SyrupRadioButton.AutoSize = true;
this.SyrupRadioButton.Location = new System.Drawing.Point(443, 177);
this.SyrupRadioButton.Name = "SyrupRadioButton";
this.SyrupRadioButton.Size = new System.Drawing.Size(52, 17);
this.SyrupRadioButton.TabIndex = 16;
this.SyrupRadioButton.TabStop = true;
this.SyrupRadioButton.Text = "Syrup";
this.SyrupRadioButton.UseVisualStyleBackColor = true;
//
// ToppingLabel
//
this.ToppingLabel.AutoSize = true;
this.ToppingLabel.Location = new System.Drawing.Point(440, 52);
this.ToppingLabel.Name = "ToppingLabel";
this.ToppingLabel.Size = new System.Drawing.Size(57, 13);
this.ToppingLabel.TabIndex = 17;
this.ToppingLabel.Text = "Toppings :";
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(530, 324);
this.Controls.Add(this.ToppingLabel);
this.Controls.Add(this.SyrupRadioButton);
this.Controls.Add(this.CandiesRadioButton);
this.Controls.Add(this.OrangeCheckBox);
this.Controls.Add(this.BerryCheckBox);
this.Controls.Add(this.PistachioCheckBox);
this.Controls.Add(this.VanillaCheckBox);
this.Controls.Add(this.BiscuitRadioButton);
this.Controls.Add(this.ChocolateCheckBox);
this.Controls.Add(this.ScoopLabel);
this.Controls.Add(this.FlavorLabel);
this.Controls.Add(this.CheckLabel);
this.Controls.Add(this.ExitButton);
this.Controls.Add(this.ClearButton);
this.Controls.Add(this.ScoopsComboBox);
this.Controls.Add(this.AddButton);
this.Controls.Add(this.CheckTextBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "MainForm";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox CheckTextBox;
private System.Windows.Forms.Button AddButton;
private System.Windows.Forms.ComboBox ScoopsComboBox;
private System.Windows.Forms.Button ClearButton;
private System.Windows.Forms.Button ExitButton;
private System.Windows.Forms.Label CheckLabel;
private System.Windows.Forms.Label FlavorLabel;
private System.Windows.Forms.Label ScoopLabel;
private System.Windows.Forms.CheckBox ChocolateCheckBox;
private System.Windows.Forms.RadioButton BiscuitRadioButton;
private System.Windows.Forms.CheckBox VanillaCheckBox;
private System.Windows.Forms.CheckBox PistachioCheckBox;
private System.Windows.Forms.CheckBox BerryCheckBox;
private System.Windows.Forms.CheckBox OrangeCheckBox;
private System.Windows.Forms.RadioButton CandiesRadioButton;
private System.Windows.Forms.RadioButton SyrupRadioButton;
private System.Windows.Forms.Label ToppingLabel;
}
}
Comments
Leave a comment