Advertisement
Dennisaa

Simple calculator in WinForms

May 9th, 2015
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.85 KB | None | 0 0
  1. //Form1.cs
  2.   private void AddButton_Click(object sender, EventArgs e) {
  3.             if (FirstNumber.Text == "" && SecondNumber.Text == "") {
  4.                 Answer.Text = "";
  5.                 return;
  6.             }
  7.             this.Answer.Text = ((Int32.Parse(FirstNumber.Text)) + (Int32.Parse(SecondNumber.Text))).ToString();
  8.         }
  9.  
  10. // Form1.Designer.cs
  11. namespace WindowsFormsApplication1 {
  12.     partial class Form1 {
  13.         /// <summary>
  14.         /// Required designer variable.
  15.         /// </summary>
  16.         private System.ComponentModel.IContainer components = null;
  17.  
  18.         /// <summary>
  19.         /// Clean up any resources being used.
  20.         /// </summary>
  21.         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  22.         protected override void Dispose(bool disposing) {
  23.             if (disposing && (components != null)) {
  24.                 components.Dispose();
  25.             }
  26.             base.Dispose(disposing);
  27.         }
  28.  
  29.         #region Windows Form Designer generated code
  30.  
  31.         /// <summary>
  32.         /// Required method for Designer support - do not modify
  33.         /// the contents of this method with the code editor.
  34.         /// </summary>
  35.         private void InitializeComponent() {
  36.             this.AddButton = new System.Windows.Forms.Button();
  37.             this.FirstNumber = new System.Windows.Forms.TextBox();
  38.             this.label1 = new System.Windows.Forms.Label();
  39.             this.SecondNumber = new System.Windows.Forms.TextBox();
  40.             this.label3 = new System.Windows.Forms.Label();
  41.             this.label4 = new System.Windows.Forms.Label();
  42.             this.Answer = new System.Windows.Forms.TextBox();
  43.             this.SuspendLayout();
  44.             //
  45.             // AddButton
  46.             //
  47.             this.AddButton.Location = new System.Drawing.Point(128, 76);
  48.             this.AddButton.Name = "AddButton";
  49.             this.AddButton.Size = new System.Drawing.Size(100, 29);
  50.             this.AddButton.TabIndex = 0;
  51.             this.AddButton.Text = "Add";
  52.             this.AddButton.UseVisualStyleBackColor = true;
  53.             this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
  54.             //
  55.             // FirstNumber
  56.             //
  57.             this.FirstNumber.AccessibleRole = System.Windows.Forms.AccessibleRole.Text;
  58.             this.FirstNumber.Location = new System.Drawing.Point(128, 22);
  59.             this.FirstNumber.Name = "FirstNumber";
  60.             this.FirstNumber.Size = new System.Drawing.Size(100, 20);
  61.             this.FirstNumber.TabIndex = 1;
  62.             this.FirstNumber.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
  63.             //
  64.             // label1
  65.             //
  66.             this.label1.AutoSize = true;
  67.             this.label1.Location = new System.Drawing.Point(41, 25);
  68.             this.label1.Name = "label1";
  69.             this.label1.Size = new System.Drawing.Size(69, 13);
  70.             this.label1.TabIndex = 2;
  71.             this.label1.Text = "First Number:";
  72.             //
  73.             // SecondNumber
  74.             //
  75.             this.SecondNumber.Location = new System.Drawing.Point(128, 48);
  76.             this.SecondNumber.Name = "SecondNumber";
  77.             this.SecondNumber.Size = new System.Drawing.Size(100, 20);
  78.             this.SecondNumber.TabIndex = 8;
  79.             this.SecondNumber.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
  80.             //
  81.             // label3
  82.             //
  83.             this.label3.AutoSize = true;
  84.             this.label3.Location = new System.Drawing.Point(41, 51);
  85.             this.label3.Name = "label3";
  86.             this.label3.Size = new System.Drawing.Size(87, 13);
  87.             this.label3.TabIndex = 9;
  88.             this.label3.Text = "Second Number:";
  89.             this.label3.Click += new System.EventHandler(this.label3_Click);
  90.             //
  91.             // label4
  92.             //
  93.             this.label4.AutoSize = true;
  94.             this.label4.Location = new System.Drawing.Point(41, 111);
  95.             this.label4.Name = "label4";
  96.             this.label4.Size = new System.Drawing.Size(45, 13);
  97.             this.label4.TabIndex = 10;
  98.             this.label4.Text = "Answer:";
  99.             //
  100.             // Answer
  101.             //
  102.             this.Answer.AccessibleRole = System.Windows.Forms.AccessibleRole.Text;
  103.             this.Answer.Location = new System.Drawing.Point(128, 111);
  104.             this.Answer.Name = "Answer";
  105.             this.Answer.ReadOnly = true;
  106.             this.Answer.Size = new System.Drawing.Size(100, 20);
  107.             this.Answer.TabIndex = 11;
  108.             this.Answer.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
  109.             //
  110.             // Form1
  111.             //
  112.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  113.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  114.             this.ClientSize = new System.Drawing.Size(269, 146);
  115.             this.Controls.Add(this.Answer);
  116.             this.Controls.Add(this.label4);
  117.             this.Controls.Add(this.label3);
  118.             this.Controls.Add(this.SecondNumber);
  119.             this.Controls.Add(this.label1);
  120.             this.Controls.Add(this.FirstNumber);
  121.             this.Controls.Add(this.AddButton);
  122.             this.Name = "Form1";
  123.             this.Text = "Simple Calculator";
  124.             this.ResumeLayout(false);
  125.             this.PerformLayout();
  126.  
  127.         }
  128.  
  129.         #endregion
  130.  
  131.         private System.Windows.Forms.Button AddButton;
  132.         private System.Windows.Forms.TextBox FirstNumber;
  133.         private System.Windows.Forms.Label label1;
  134.         private System.Windows.Forms.TextBox SecondNumber;
  135.         private System.Windows.Forms.Label label3;
  136.         private System.Windows.Forms.Label label4;
  137.         private System.Windows.Forms.TextBox Answer;
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement