I'm looking to get this cleaned up.
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BaseHexWinCalc
{
public partial class MainCalcForm : Form
{
enum MathFunction
{
Plus,
Minus,
Multiply,
Divide
}
public void Splash_Start()
{
Application.Run(new _Splash_Form());
}
public MainCalcForm(String name)
{
Thread loadSplash = new Thread(new ThreadStart(Splash_Start));
loadSplash.Start();
Thread.Sleep(5000);
InitializeComponent();
this.Text = name;
loadSplash.Abort();
}
#region Operator Events
private void Button_Ops_Click(object sender, EventArgs e)
{
try
{
MathFunction _MathFunction_Desired;
Button selected = (Button)sender;
String OpsVal = selected.Text;
String text = _TextBox_Output.Text;
Double _Double_FirstInput = Double.Parse(text);
_Label_Current.Text += (text + OpsVal);
switch (OpsVal)
{
case "+":
_MathFunction_Desired = MathFunction.Plus;
break;
case "-":
_MathFunction_Desired = MathFunction.Minus;
break;
case "*":
_MathFunction_Desired = MathFunction.Multiply;
break;
case "/":
_MathFunction_Desired = MathFunction.Divide;
break;
default:
break;
}
_TextBox_Output.Clear();
}
catch { MessageBox.Show(" You must enter a value first."); }
}
#endregion
#region Equals Function
private void Button_Equals_Click(object sender, EventArgs e)
{
DataTable solutionFinder = new DataTable();
String finText = _Label_Current.Text + _TextBox_Output.Text;
if (finText.Contains("/0"))
_TextBox_Final.Text = "No division by Zero";
else
try
{
double finalSolution = Convert.ToDouble(solutionFinder.Compute(finText, ""));
_TextBox_Final.Text = (finalSolution.ToString());
}
catch { MessageBox.Show(" You must enter value first."); }
_TextBox_Output.Clear();
_Label_Current.Text = String.Empty;
}
#endregion
#region Number Entries
private void Button_Numeral_Click(object sender, EventArgs e)
{
try
{
Button selected = (Button)sender;
String NumVal = selected.Text;
switch (NumVal)
{
case "1":
_TextBox_Output.Text += NumVal;
break;
case "2":
_TextBox_Output.Text += NumVal;
break;
case "3":
_TextBox_Output.Text += NumVal;
break;
case "4":
_TextBox_Output.Text += NumVal;
break;
case "5":
_TextBox_Output.Text += NumVal;
break;
case "6":
_TextBox_Output.Text += NumVal;
break;
case "7":
_TextBox_Output.Text += NumVal;
break;
case "8":
_TextBox_Output.Text += NumVal;
break;
case "9":
_TextBox_Output.Text += NumVal;
break;
case "0":
_TextBox_Output.Text += NumVal;
break;
default:
break;
}
}
catch { MessageBox.Show("Not a valid entry"); }
}
#endregion
#region Hex Entries
private void Button_Hex_Click(object sender, EventArgs e)
{
try
{
Button selected = (Button)sender;
String HexVal = selected.Text;
switch (HexVal)
{
case "A":
_TextBox_Output.Text += HexVal;
break;
case "B":
_TextBox_Output.Text += HexVal;
break;
case "C":
_TextBox_Output.Text += HexVal;
break;
case "D":
_TextBox_Output.Text += HexVal;
break;
case "E":
_TextBox_Output.Text += HexVal;
break;
case "F":
_TextBox_Output.Text += HexVal;
break;
default:
break;
}
}
catch { MessageBox.Show("Not a valid entry"); }
}
#endregion
#region Non-Numeric Features
private void Button_Dec_Click(object sender, EventArgs e)
{
_TextBox_Output.Text += ".";
}
private void _Button_Clr_Click(object sender, EventArgs e)
{
_TextBox_Output.Clear();
}
#endregion
#region Converter
private void Button_MainConvert_Click(object sender, EventArgs e)
{
if (_TextBox_Output.Text == String.Empty)
_TextBox_Output.Text = "0";
Button selected = (Button)sender;
bool conCase = selected.Text.Contains("To Hex");
if (conCase)
{
int numConvert;
String finHex;
if (Int32.TryParse(_TextBox_Output.Text, out numConvert))
{
finHex = String.Format("{0:x}", numConvert);//create hex
_TextBox_Output.Clear();
_TextBox_Final.Text = finHex.ToUpper();//hex output
selected.Text = "To Dec!";
HexLayout.Visible = true;
OperatorsLayout.Visible =
_Button_Equals.Visible =
_Button_Dec.Enabled = false;
} else {
_TextBox_Final.Text = "Invalid";
_TextBox_Output.Clear();
}
}
else
{
int newDec = Convert.ToInt32(_TextBox_Output.Text, 16);
_TextBox_Output.Text = String.Empty;
_TextBox_Final.Text = newDec.ToString();
selected.Text = "To Hex!";
HexLayout.Visible = false;
OperatorsLayout.Visible =
_Button_Equals.Visible =
_Button_Dec.Enabled = true;
}
}
#endregion
}
}