title: 'Simple' Calculator - C# (Set focus on text box 2...)
body: <p>To give you all a bit of my programming background, I'm a first year Software Engineering Student (started this academic year). I've been programming for the best part of a year, mainly using HTML and Python. The language I will be using throughout my degree is C#. (I'm still fairly new to this programming language) and the IDE being used is Visual Studio 2013.</p>
  
  <p>As I've literally just started my course 3 weeks ago, I was given a task to do. It was to create a simple calculator which can add, subtract, multiply, divide various numbers from user input. This I have done, as well as implementing a way for users to do maths with floating points. </p>
  
  <p>In order to make the calculator a bit more user friendly, I decided to add number buttons, based on the layout of the Windows Calculator. It has two input text boxes and one output text box which allows users to copy and then paste their answer into other documents etc. I've only got 4 operator buttons which are; +,-,*,/. In addition, I also added an 'Exit' button. </p>
  
  <p>Whenever the user inputs the two values, they have to press one of the operator buttons. For example; if the user types in <strong>10</strong> in <strong>'txtNum1'</strong> and <strong>20</strong> in <strong>'txtNum2'</strong> and presses <strong>'btnAdd'</strong>, the value of the sum will be represented in <strong>'txtAnswer'</strong>.</p>
  
  <p>(I would provide an image of the form but I require at least 10 reputation points on this website, so apologies in advance)</p>
  
  <p>The issues which I'm having with the form are;
  - I can only input values into one text box (using the mouse + available buttons on screen). I've tried using boolean in order to check whether '<strong>Focus</strong>' has been set to a particular box and then going from there but I'm completely lost on what to do next. My lecturer actually advised me to use this boolean method in order to help solve the issue. </p>
  
  <p>Any advice is greatly appreciated + I would appreciate it if you guys taught me a better way of representing my code, maybe reduce the amount by using functions etc. I'm always keen to learn new tips + tricks. </p>
  
  <p>Here's the source code:</p>
  
  <pre><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 AddUpNums
  {
      public partial class Form1 : Form
      {
          Boolean ff;
  
          public Form1()
          {
              InitializeComponent();
          }
  
          private void button2_Click(object sender, EventArgs e)
          {
              Environment.Exit(0);
          }
  
          private void checkForEmptySpace()
          {
              if (txtNum1.Text == "")
                  txtNum1.Text = "0";
              if (txtNum2.Text == "")
                  txtNum2.Text = "0";
          }
  
          private void btnAddUp_Click(object sender, EventArgs e)
          {
              checkForEmptySpace();
              double num1, num2, sum;
              num1 = double.Parse(txtNum1.Text);
              num2 = double.Parse(txtNum2.Text);
              sum = num1 + num2;
              txtAnswer.Text = Convert.ToString(sum);
  
          }
  
          private void btnSubtract_Click(object sender, EventArgs e)
          {
              checkForEmptySpace();
              double num1, num2, sum;
              num1 = double.Parse(txtNum1.Text);
              num2 = double.Parse(txtNum2.Text);
              sum = num1 - num2;
              txtAnswer.Text = Convert.ToString(sum);
          }
  
          private void btnMultiply_Click(object sender, EventArgs e)
          {
              checkForEmptySpace();
              double num1, num2, sum;
              num1 = double.Parse(txtNum1.Text);
              num2 = double.Parse(txtNum2.Text);
              sum = num1 * num2;
              txtAnswer.Text = Convert.ToString(sum);
          }
  
          private void btnDivide_Click(object sender, EventArgs e)
          {
              checkForEmptySpace();
              double num1, num2, sum;
              num1 = double.Parse(txtNum1.Text);
              num2 = double.Parse(txtNum2.Text);
              sum = num1 / num2;
              txtAnswer.Text = Convert.ToString(sum);
          }
  
          private void btn0_Click(object sender, EventArgs e)
          {
              //txtNum2.Focus();
              //if (txtNum2.Focus() == true)
              //   txtNum2.Text += "0";
              //if (txtNum1.Focus() == true)
              //   txtNum1.Text += "0";
  
  
          }
  
          private void btn1_Click(object sender, EventArgs e)
          {
              txtNum1.Text += "1";
              if (ff)
                  txtNum2.Text += "1";
  
          }
  
          private void txtNum1_TextChanged(object sender, EventArgs e)
          {
  
          }
  
  
  
          private void txtNum2_MouseClick(object sender, MouseEventArgs e)
          {
  
              ff = true;
  
          }
      }
  }
  </code></pre>