C# :: Aufgabe #274

3 Lösungen Lösungen öffentlich

Windows Forms Taschenrechner

Anfänger - C# von paddlboot - 04.12.2019 um 17:09 Uhr
Erstelle mit Hilfe von Windows Forms einen Taschenrechner!

- Der Taschenrechner soll zwei Zahlen speichern können.
- Wie bei einem Taschenrechner üblich, sollen alle Zahleneingaben gesammelt werden bis der Operator gewählt wurde.
- Mit jedem Drücken einer Zahlentaste wird der Variable also eine Dezimalstelle hinzugefügt.
- Wenn ein Operator ausgewählt wurde, soll die erste eingegebene Zahl gespeichert werden, ebenso der Operator (in einer separaten Variable).
- Mit Drücken der Ergebnis Taste (=) soll das Ergebnis in der selben Textbox ausgegeben werden, wie die, in der die Zahlen eingegeben wurden.

Im Anhang ein Beispiel wie ich das gelöst habe.

Lösungen:

vote_ok
von Kotgreifer (1100 Punkte) - 18.12.2019 um 11:04 Uhr
Ich arbeite normalerweise nur mit WPF deswegen weiß ich net ob es reicht den Designer zu kopieren :D
Wenn man mehr für die UI braucht dann glaubt einfach dran das es funktioniert.
Tatsächlich kannte ich noch keinen Weg mehrer Zahlen hintereinander zusammen zurechnen und auf die Punkt vor Strich Regel zu achten.
Daher habe ich mir selbst einen Weg überlegt.


Quellcode ausblenden C#-Code
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Taschenrechner
{
	public partial class Form1 : Form
	{
		List<String> numbers = new List<String>();
		public Form1()
		{
			InitializeComponent();
		}

		private void Number_Click(object sender, EventArgs e)
		{
			Button tmpBtn = (Button)sender;
			labelActive.Text += tmpBtn.Text;
		
		}

		private void Operator_Click(object sender, EventArgs e)
		{
			if (labelActive.Text !="")
			{
				Button tmpBtn = (Button)sender;
				numbers.Add(labelActive.Text);
				numbers.Add(tmpBtn.Text);
				labelPassiv.Text += labelActive.Text+tmpBtn.Text;
				labelActive.Text = null;

			}
		}

		private void zDelete_Click(object sender, EventArgs e)
		{
			numbers = new List<string>();
			labelActive.Text = string.Empty;
			labelPassiv.Text = string.Empty;
		}


		private void zResult_Click(object sender, EventArgs e)
		{
			if (labelActive.Text != "")
			{
				numbers.Add(labelActive.Text);
				labelPassiv.Text += labelActive.Text + "=";
				labelActive.Text = null;

				if (numbers.Contains("*") || numbers.Contains("/"))
				{
					PunktVorStrich();
				}

				for (int i = 0; i < numbers.Count; i++)
				{
					if (numbers.Count == 1)
						break;


					if (numbers[1] == "+")
					{
						int.TryParse(numbers[0], out int num1);
						int.TryParse(numbers[2], out int num2);
						double erg = num1 + num2;
						numbers[0] = erg.ToString();
						numbers.RemoveAt(1);
						numbers.RemoveAt(1);

					}
					else if (numbers[1] == "-")
					{
						int.TryParse(numbers[0], out int num1);
						int.TryParse(numbers[2], out int num2);
						double erg = num1 - num2;
						numbers[0] = erg.ToString();
						numbers.RemoveAt(1);
						numbers.RemoveAt(1);

					}
				}
				labelActive.Text = numbers[0];
			}
		}



		private void PunktVorStrich()
		{
			for (int i = 1; i < numbers.Count; i++)
			{
				if (numbers[i] == "*")
				{
					int.TryParse(numbers[i - 1], out int num1);
					int.TryParse(numbers[i + 1], out int num2);
					double erg = num1 * num2;
					numbers[i - 1] = erg.ToString();
					numbers.RemoveAt(i);
					numbers.RemoveAt(i);
					i -= 2;
				}
				else if (numbers[i] == "/")
				{
					int.TryParse(numbers[i - 1], out int num1);
					int.TryParse(numbers[i + 1], out int num2);
					double erg = num1 / num2;
					numbers[i - 1] = erg.ToString();
					numbers.RemoveAt(i);
					numbers.RemoveAt(i);
					i -= 2;
				}

			}
		}

	}
}




Quellcode ausblenden C#-Code
namespace Taschenrechner
{
	partial class Form1
	{
		/// <summary>
		/// Erforderliche Designervariable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// Verwendete Ressourcen bereinigen.
		/// </summary>
		/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Vom Windows Form-Designer generierter Code

		/// <summary>
		/// Erforderliche Methode für die Designerunterstützung.
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
		/// </summary>
		private void InitializeComponent()
		{
			this.b1 = new System.Windows.Forms.Button();
			this.b2 = new System.Windows.Forms.Button();
			this.labelActive = new System.Windows.Forms.Label();
			this.b3 = new System.Windows.Forms.Button();
			this.b4 = new System.Windows.Forms.Button();
			this.b5 = new System.Windows.Forms.Button();
			this.b6 = new System.Windows.Forms.Button();
			this.b7 = new System.Windows.Forms.Button();
			this.b8 = new System.Windows.Forms.Button();
			this.b9 = new System.Windows.Forms.Button();
			this.zPlus = new System.Windows.Forms.Button();
			this.zMinus = new System.Windows.Forms.Button();
			this.zMal = new System.Windows.Forms.Button();
			this.zGeteilt = new System.Windows.Forms.Button();
			this.zGleich = new System.Windows.Forms.Button();
			this.zDelete = new System.Windows.Forms.Button();
			this.b0 = new System.Windows.Forms.Button();
			this.labelPassiv = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// b1
			// 
			this.b1.Location = new System.Drawing.Point(30, 168);
			this.b1.Name = "b1";
			this.b1.Size = new System.Drawing.Size(30, 30);
			this.b1.TabIndex = 0;
			this.b1.Text = "1";
			this.b1.UseVisualStyleBackColor = true;
			this.b1.Click += new System.EventHandler(this.Number_Click);
			// 
			// b2
			// 
			this.b2.Location = new System.Drawing.Point(66, 168);
			this.b2.Name = "b2";
			this.b2.Size = new System.Drawing.Size(30, 30);
			this.b2.TabIndex = 1;
			this.b2.Text = "2";
			this.b2.UseVisualStyleBackColor = true;
			this.b2.Click += new System.EventHandler(this.Number_Click);
			// 
			// labelActive
			// 
			this.labelActive.BackColor = System.Drawing.SystemColors.ActiveBorder;
			this.labelActive.Location = new System.Drawing.Point(30, 63);
			this.labelActive.Name = "labelActive";
			this.labelActive.Size = new System.Drawing.Size(138, 20);
			this.labelActive.TabIndex = 2;
			// 
			// b3
			// 
			this.b3.Location = new System.Drawing.Point(102, 168);
			this.b3.Name = "b3";
			this.b3.Size = new System.Drawing.Size(30, 30);
			this.b3.TabIndex = 3;
			this.b3.Text = "3";
			this.b3.UseVisualStyleBackColor = true;
			this.b3.Click += new System.EventHandler(this.Number_Click);
			// 
			// b4
			// 
			this.b4.Location = new System.Drawing.Point(30, 132);
			this.b4.Name = "b4";
			this.b4.Size = new System.Drawing.Size(30, 30);
			this.b4.TabIndex = 4;
			this.b4.Text = "4";
			this.b4.UseVisualStyleBackColor = true;
			this.b4.Click += new System.EventHandler(this.Number_Click);
			// 
			// b5
			// 
			this.b5.Location = new System.Drawing.Point(66, 132);
			this.b5.Name = "b5";
			this.b5.Size = new System.Drawing.Size(30, 30);
			this.b5.TabIndex = 5;
			this.b5.Text = "5";
			this.b5.UseVisualStyleBackColor = true;
			this.b5.Click += new System.EventHandler(this.Number_Click);
			// 
			// b6
			// 
			this.b6.Location = new System.Drawing.Point(102, 132);
			this.b6.Name = "b6";
			this.b6.Size = new System.Drawing.Size(30, 30);
			this.b6.TabIndex = 6;
			this.b6.Text = "6";
			this.b6.UseVisualStyleBackColor = true;
			this.b6.Click += new System.EventHandler(this.Number_Click);
			// 
			// b7
			// 
			this.b7.Location = new System.Drawing.Point(30, 96);
			this.b7.Name = "b7";
			this.b7.Size = new System.Drawing.Size(30, 30);
			this.b7.TabIndex = 7;
			this.b7.Text = "7";
			this.b7.UseVisualStyleBackColor = true;
			this.b7.Click += new System.EventHandler(this.Number_Click);
			// 
			// b8
			// 
			this.b8.Location = new System.Drawing.Point(66, 96);
			this.b8.Name = "b8";
			this.b8.Size = new System.Drawing.Size(30, 30);
			this.b8.TabIndex = 8;
			this.b8.Text = "8";
			this.b8.UseVisualStyleBackColor = true;
			this.b8.Click += new System.EventHandler(this.Number_Click);
			// 
			// b9
			// 
			this.b9.Location = new System.Drawing.Point(102, 96);
			this.b9.Name = "b9";
			this.b9.Size = new System.Drawing.Size(30, 30);
			this.b9.TabIndex = 9;
			this.b9.Text = "9";
			this.b9.UseVisualStyleBackColor = true;
			this.b9.Click += new System.EventHandler(this.Number_Click);
			// 
			// zPlus
			// 
			this.zPlus.Location = new System.Drawing.Point(138, 96);
			this.zPlus.Name = "zPlus";
			this.zPlus.Size = new System.Drawing.Size(30, 30);
			this.zPlus.TabIndex = 10;
			this.zPlus.Text = "+";
			this.zPlus.UseVisualStyleBackColor = true;
			this.zPlus.Click += new System.EventHandler(this.Operator_Click);
			// 
			// zMinus
			// 
			this.zMinus.Location = new System.Drawing.Point(138, 132);
			this.zMinus.Name = "zMinus";
			this.zMinus.Size = new System.Drawing.Size(30, 30);
			this.zMinus.TabIndex = 11;
			this.zMinus.Text = "-";
			this.zMinus.UseVisualStyleBackColor = true;
			this.zMinus.Click += new System.EventHandler(this.Operator_Click);
			// 
			// zMal
			// 
			this.zMal.Location = new System.Drawing.Point(138, 168);
			this.zMal.Name = "zMal";
			this.zMal.Size = new System.Drawing.Size(30, 30);
			this.zMal.TabIndex = 12;
			this.zMal.Text = "*";
			this.zMal.UseVisualStyleBackColor = true;
			this.zMal.Click += new System.EventHandler(this.Operator_Click);
			// 
			// zGeteilt
			// 
			this.zGeteilt.Location = new System.Drawing.Point(138, 204);
			this.zGeteilt.Name = "zGeteilt";
			this.zGeteilt.Size = new System.Drawing.Size(30, 30);
			this.zGeteilt.TabIndex = 13;
			this.zGeteilt.Text = "/";
			this.zGeteilt.UseVisualStyleBackColor = true;
			this.zGeteilt.Click += new System.EventHandler(this.Operator_Click);
			// 
			// zGleich
			// 
			this.zGleich.Location = new System.Drawing.Point(102, 204);
			this.zGleich.Name = "zGleich";
			this.zGleich.Size = new System.Drawing.Size(30, 30);
			this.zGleich.TabIndex = 14;
			this.zGleich.Text = "=";
			this.zGleich.UseVisualStyleBackColor = true;
			this.zGleich.Click += new System.EventHandler(this.zResult_Click);
			// 
			// zDelete
			// 
			this.zDelete.Location = new System.Drawing.Point(66, 204);
			this.zDelete.Name = "zDelete";
			this.zDelete.Size = new System.Drawing.Size(30, 30);
			this.zDelete.TabIndex = 15;
			this.zDelete.Text = "C";
			this.zDelete.UseVisualStyleBackColor = true;
			this.zDelete.Click += new System.EventHandler(this.zDelete_Click);
			// 
			// b0
			// 
			this.b0.Location = new System.Drawing.Point(30, 204);
			this.b0.Name = "b0";
			this.b0.Size = new System.Drawing.Size(30, 30);
			this.b0.TabIndex = 16;
			this.b0.Text = "0";
			this.b0.UseVisualStyleBackColor = true;
			this.b0.Click += new System.EventHandler(this.Number_Click);
			// 
			// labelPassiv
			// 
			this.labelPassiv.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.labelPassiv.Location = new System.Drawing.Point(30, 34);
			this.labelPassiv.Name = "labelPassiv";
			this.labelPassiv.Size = new System.Drawing.Size(138, 20);
			this.labelPassiv.TabIndex = 17;
			this.labelPassiv.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(227, 242);
			this.Controls.Add(this.labelPassiv);
			this.Controls.Add(this.b0);
			this.Controls.Add(this.zDelete);
			this.Controls.Add(this.zGleich);
			this.Controls.Add(this.zGeteilt);
			this.Controls.Add(this.zMal);
			this.Controls.Add(this.zMinus);
			this.Controls.Add(this.zPlus);
			this.Controls.Add(this.b9);
			this.Controls.Add(this.b8);
			this.Controls.Add(this.b7);
			this.Controls.Add(this.b6);
			this.Controls.Add(this.b5);
			this.Controls.Add(this.b4);
			this.Controls.Add(this.b3);
			this.Controls.Add(this.labelActive);
			this.Controls.Add(this.b2);
			this.Controls.Add(this.b1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}

		#endregion

		private System.Windows.Forms.Button b1;
		private System.Windows.Forms.Button b2;
		private System.Windows.Forms.Label labelActive;
		private System.Windows.Forms.Button b3;
		private System.Windows.Forms.Button b4;
		private System.Windows.Forms.Button b5;
		private System.Windows.Forms.Button b6;
		private System.Windows.Forms.Button b7;
		private System.Windows.Forms.Button b8;
		private System.Windows.Forms.Button b9;
		private System.Windows.Forms.Button zPlus;
		private System.Windows.Forms.Button zMinus;
		private System.Windows.Forms.Button zMal;
		private System.Windows.Forms.Button zGeteilt;
		private System.Windows.Forms.Button zGleich;
		private System.Windows.Forms.Button zDelete;
		private System.Windows.Forms.Button b0;
		private System.Windows.Forms.Label labelPassiv;
	}
}

vote_ok
von Exception (5030 Punkte) - 22.12.2019 um 09:21 Uhr
Form1.cs
Quellcode ausblenden C#-Code
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace _274_Taschenrechner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.InitControls();
        }

        private void InitControls()
        {
            this.Width = 350;
            this.Height = 400;
            this.BackColor = Color.Green;
            this.MaximizeBox = false;
            this.FormBorderStyle = FormBorderStyle.Fixed3D;
            this.Text = "A Simple Green Calculator";

            TextBox t = new TextBox();
            t.Name = "output";
            t.Width = this.Width - 40;
            t.ReadOnly = true;
            t.Location = new Point(10, 10);

            this.Controls.Add(t);

            int size = 50;
            int x = this.Width - 100, y = t.Bottom + 20;

            Button b;

            for (int i = 9; i >= 1; i--)
            {
                b = new Button();
                b.Name = "" + i;
                b.Text = b.Name;
                b.Width = size;
                b.Height = size;
                b.FlatStyle = FlatStyle.Flat;
                b.BackColor = Color.LightGreen;
                b.Click += Click_Digit;

                if (i % 3 == 0 && i != 9)
                {
                    y += 75;
                    x = this.Width - 175;
                }
                else
                {
                    x -= 75;
                }

                b.Location = new Point(x, y);

                this.Controls.Add(b);
            }

            x = 28;

            b = new Button();
            b.Name = "" + 0;
            b.Text = b.Name;
            b.Width = size;
            b.Height = size;
            b.FlatStyle = FlatStyle.Flat;
            b.BackColor = Color.LightGreen;
            b.Location = new Point(x, y + 75);
            b.Click += Click_Digit;
            this.Controls.Add(b);

            x += 75;

            b = new Button();
            b.Name = "C";
            b.Text = b.Name;
            b.Width = size;
            b.Height = size;
            b.FlatStyle = FlatStyle.Flat;
            b.BackColor = Color.LightPink;
            b.Location = new Point(x, y + 75);
            b.Click += Click_Reset;
            this.Controls.Add(b);

            x += 75;

            b = new Button();
            b.Name = "=";
            b.Text = b.Name;
            b.Width = size;
            b.Height = size;
            b.FlatStyle = FlatStyle.Flat;
            b.BackColor = Color.Gold;
            b.Location = new Point(x, y + 75);
            b.Click += Click_Calculate;
            this.Controls.Add(b);

            x = this.Width - 100;
            y = t.Bottom + 20;

            List<string> operators = new List<string>() { "+", "-", "*", "/" };

            foreach(string s in operators)
            {
                b = new Button();
                b.Name = s;
                b.Text = b.Name;
                b.Width = size;
                b.Height = size;
                b.FlatStyle = FlatStyle.Flat;
                b.BackColor = Color.LightSkyBlue;
                b.Location = new Point(x, y);
                b.Click += Click_Operator;

                y += 75;

                this.Controls.Add(b);
            }
        }

        private TextBox getOutputTextbox()
        {
            return this.Controls.Find("output", true).FirstOrDefault() as TextBox;
        }

        private void Click_Digit(object sender, EventArgs e)
        {
            Button b = sender as Button;
            TextBox tb = this.getOutputTextbox();
            tb.Text += b.Name;
        }

        private void Click_Reset(object sender, EventArgs e)
        {
            TextBox tb = this.getOutputTextbox();
            tb.Clear();
        }

        private void Click_Calculate(object sender, EventArgs e)
        {
            TextBox tb = this.getOutputTextbox();
            tb.Text = new DataTable().Compute(tb.Text, null).ToString();
        }
        

        private void Click_Operator(object sender, EventArgs e)
        {
            Button b = sender as Button;
            TextBox tb = this.getOutputTextbox();
            tb.Text += b.Name;
        }
    }
}


Form1.Designer.cs
Quellcode ausblenden C#-Code
namespace _274_Taschenrechner
{
    partial class Form1
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(182, 25);
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion
    }
}
1 Kommentar
1x
vote_ok
von Waldgeist (390 Punkte) - 23.12.2019 um 13:45 Uhr
Quellcode ausblenden C#-Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Aufgabe_274_Taschenrechner
{
    public partial class Form1 : Form
    {
        public string Zahl = "";
        public string Calc = "";       
            
        public Form1()
        {
            InitializeComponent();
        }

        private void Taste_0_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += "0";
        }

        private void Taste_1_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += "1";
        }

        private void Taste_2_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += "2";
        }

        private void Taste_3_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += "3";
        }

        private void Taste_4_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += "4";
        }

        private void Taste_5_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += "5";
        }

        private void Taste_6_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += "6";
        }

        private void Taste_7_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += "7";
        }

        private void Taste_8_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += "8";
        }

        private void Taste_9_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += "9";
        }

        private void Taste_Komma_Click(object sender, EventArgs e)
        {
            Ausgabe.Text += ",";
        }

        private void Taste_DEL_Click(object sender, EventArgs e)
        {
            if (Ausgabe.Text.Length > 0) 
            {
                Ausgabe.Text = Ausgabe.Text.Substring(0, Ausgabe.Text.Length - 1);
            }
        
        }

        private void Taste_AC_Click(object sender, EventArgs e)
        {
            Zahl = "";
            Calc = "";
            Ausgabe.Text = "";
            Label1.Text = "";
            Label2.Text = "";
        }

        private void Taste_Minus_Click(object sender, EventArgs e)
        {
            Zahl = Ausgabe.Text;
            Label2.Text = Zahl;
            Ausgabe.Text = "";
            Calc = "-";
            Label1.Text = Calc;
        }

        private void Taste_Plus_Click(object sender, EventArgs e)
        {
            Zahl = Ausgabe.Text;
            Label2.Text = Zahl;
            Ausgabe.Text = "";
            Calc = "+";
            Label1.Text = Calc;
        }

        private void Taste_MAL_Click(object sender, EventArgs e)
        {
            Zahl = Ausgabe.Text;
            Label2.Text = Zahl;
            Ausgabe.Text = "";
            Calc = "*";
            Label1.Text = Calc;
        }

        private void Taste_Geteilt_Click(object sender, EventArgs e)
        {
            Zahl = Ausgabe.Text;
            Label2.Text = Zahl;
            Ausgabe.Text = "";
            Calc = "/";
            Label1.Text = Calc;
        }

        private void Taste_Gleich_Click(object sender, EventArgs e)
        {
            if (Calc == "+") 
                {
                Ausgabe.Text = Convert.ToString(Convert.ToDouble(Zahl) + Convert.ToDouble(Ausgabe.Text));
                }

            if (Calc == "-")
            {
                Ausgabe.Text = Convert.ToString(Convert.ToDouble(Zahl) - Convert.ToDouble(Ausgabe.Text));
            }

            if (Calc == "*")
            {
                Ausgabe.Text = Convert.ToString(Convert.ToDouble(Zahl) * Convert.ToDouble(Ausgabe.Text));
            }

            if (Calc == "/")
            {
                Ausgabe.Text = Convert.ToString(Convert.ToDouble(Zahl) / Convert.ToDouble(Ausgabe.Text));
            }


            Label1.Text = "";
            Label2.Text = "";
        }
    }
}