Added auto compute function and toggle.

This commit is contained in:
2022-10-04 21:48:13 -05:00
parent 7c7f077705
commit e911fc48d2
13 changed files with 106 additions and 50 deletions

View File

@@ -32,40 +32,12 @@ namespace WindowsFormsApplication1
public Form1()
{
InitializeComponent();
ToolTip toolTip = new ToolTip();
toolTip.SetToolTip(autoCompute, "Automatically computes input based on changes made to textbox contents.");
}
private void currentFocus(string focusOn) {
switch (focusOn)
{
case "binaryTextBox":
binaryTextBox.Focus();
break;
case "hexTextBox":
hexTextBox.Focus();
break;
case "octalTextBox":
octalTextBox.Focus();
break;
case "decimalTextBox":
decimalTextBox.Focus();
break;
default:
this.Focus();
break;
}
}
private void clearTextboxes()
{
hexTextBox.Text = "0";
binaryTextBox.Text = "0";
octalTextBox.Text = "0";
decimalTextBox.Text = "0";
}
private void computeButton_Click(object sender, EventArgs e)
private void compute()
{
// Define variables
long decimalNum = 0, hexNum = 0, binNum = 0, octalNum = 0;
@@ -93,7 +65,8 @@ namespace WindowsFormsApplication1
//Refocus the textbox when done.
currentFocus("decimalTextBox");
}
if (octalRadioButton.Checked) {
if (octalRadioButton.Checked)
{
// The octal radio button is pressed.
hexNum = octalNum;
binNum = octalNum;
@@ -125,9 +98,39 @@ namespace WindowsFormsApplication1
hexTextBox.Text = hexNum.ToString("X");
binaryTextBox.Text = Convert.ToString(binNum, 2);
octalTextBox.Text = Convert.ToString(octalNum, 8);
}
private void currentFocus(string focusOn) {
switch (focusOn)
{
case "binaryTextBox":
binaryTextBox.Focus();
break;
case "hexTextBox":
hexTextBox.Focus();
break;
case "octalTextBox":
octalTextBox.Focus();
break;
case "decimalTextBox":
decimalTextBox.Focus();
break;
default:
this.Focus();
break;
}
}
private void clearTextboxes()
{
hexTextBox.Text = "0";
binaryTextBox.Text = "0";
octalTextBox.Text = "0";
decimalTextBox.Text = "0";
}
private void computeButton_Click(object sender, EventArgs e)
{
compute();
}
private void clearButton_Click(object sender, EventArgs e)
@@ -170,5 +173,29 @@ namespace WindowsFormsApplication1
{
currentFocus("octalTextBox");
}
private void binaryTextBox_TextChanged(object sender, EventArgs e)
{
if (autoCompute.Checked)
compute();
}
private void hexTextBox_TextChanged(object sender, EventArgs e)
{
if (autoCompute.Checked)
compute();
}
private void octalTextBox_TextChanged(object sender, EventArgs e)
{
if (autoCompute.Checked)
compute();
}
private void decimalTextBox_TextChanged(object sender, EventArgs e)
{
if (autoCompute.Checked)
compute();
}
}
}