Skip to content

Commit

Permalink
Version 2.2 - minor bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AliAlmasi committed Apr 28, 2024
1 parent 716265c commit 7cce954
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 85 deletions.
Binary file modified RadixConvertPractice.v11.suo
Binary file not shown.
32 changes: 20 additions & 12 deletions RadixConvertPractice/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 72 additions & 61 deletions RadixConvertPractice/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace RadixConvertPractice {
public partial class Form1: Form {
public static bool hasFirstGenerated = false; // checks if anything has beem generated from the time program started.
public Form1() {
InitializeComponent();
}
Expand All @@ -20,24 +21,26 @@ private void button1_Click(object sender, EventArgs e) {
}

private void Form1_Load(object sender, EventArgs e) {
this.Text = Program.msgTitle;
baseList.SelectedIndex = Settings.Default.selectedBase;
answerBase.SelectedIndex = 2;
lenTxb.Text = Settings.Default.enteredLength.ToString();
label6.Text = "v" + Program.appVersion;
}

private void genButton_Click(object sender, EventArgs e) {
hasFirstGenerated = true;
string selected = baseList.SelectedItem.ToString();
if (selected == "") {
MessageBox.Show("no number base selected", Program.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
Program.showError("no number base selected");
} else {
int len = 0;
try {
len = int.Parse(lenTxb.Text);
Settings.Default.enteredLength = len;
Settings.Default.Save();
} catch (Exception ex) {
MessageBox.Show("please enter a valid number length.\n\n" + ex.Message, Program.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
Program.showError("please enter a valid number length.\n\n" + ex.Message);
}
switch (selected) {
case "Binary - 2":
Expand All @@ -57,7 +60,7 @@ private void genButton_Click(object sender, EventArgs e) {
genTextbox.Text = hexGen;
break;
default:
MessageBox.Show("no number base selected", Program.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
Program.showError("no number base selected");
break;
}
}
Expand All @@ -75,61 +78,67 @@ private void comboBox_SelectedIndexChanged(object sender, EventArgs e) {
}

private void answerButton_Click(object sender, EventArgs e) {
if (timer1.Enabled) {
timer1.Stop();
timer1.Start();
}
string selectedAnswerBase = answerBase.SelectedItem.ToString();
int fromBase = 0;
switch (baseList.SelectedIndex) {
case 0:
fromBase = 2;
break;
case 1:
fromBase = 8;
break;
case 2:
fromBase = 10;
break;
case 3:
fromBase = 16;
break;
default:
MessageBox.Show("couldn't figure out the generated number base", Program.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
answerLabel.Visible = true;
switch (selectedAnswerBase) {
case "Binary - 2":
try {
answerLabel.Text = Convert.ToString(Convert.ToInt32(genTextbox.Text, fromBase), 2);
} catch (Exception) {
MessageBox.Show("error while converting base of generated number.", Program.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
break;
case "Octal - 8":
try {
answerLabel.Text = Convert.ToString(Convert.ToInt32(genTextbox.Text, fromBase), 8);
} catch (Exception) {
MessageBox.Show("error while converting base of generated number.", Program.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
} break;
case "Decimal - 10":
try {
answerLabel.Text = Convert.ToString(Convert.ToInt32(genTextbox.Text, fromBase), 10);
} catch (Exception) {
MessageBox.Show("error while converting base of generated number.", Program.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
} break;
case "Hexadecimal - 16":
try {
answerLabel.Text = Convert.ToString(Convert.ToInt32(genTextbox.Text, fromBase), 16).ToUpper();
} catch (Exception) {
MessageBox.Show("error while converting base of generated number.", Program.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
} break;
default:
MessageBox.Show("error while converting base of generated number.", Program.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
timer1.Enabled = true;
if (hasFirstGenerated) {
if (genTextbox.Text == "error") {
Program.showError("generate a number first.");
return;
}
if (timer1.Enabled) {
timer1.Stop();
timer1.Start();
}
string selectedAnswerBase = answerBase.SelectedItem.ToString();
int fromBase = 0;
switch (baseList.SelectedIndex) {
case 0:
fromBase = 2;
break;
case 1:
fromBase = 8;
break;
case 2:
fromBase = 10;
break;
case 3:
fromBase = 16;
break;
default:
Program.showError("couldn't figure out the generated number base");
break;
}
answerLabel.Visible = true;
switch (selectedAnswerBase) {
case "Binary - 2":
try {
answerLabel.Text = Convert.ToString(Convert.ToInt32(genTextbox.Text, fromBase), 2);
} catch (Exception) {
Program.showError("error while converting base of generated number.");
}
break;
case "Octal - 8":
try {
answerLabel.Text = Convert.ToString(Convert.ToInt32(genTextbox.Text, fromBase), 8);
} catch (Exception) {
Program.showError("error while converting base of generated number.");
} break;
case "Decimal - 10":
try {
answerLabel.Text = Convert.ToString(Convert.ToInt32(genTextbox.Text, fromBase), 10);
} catch (Exception) {
Program.showError("error while converting base of generated number.");
} break;
case "Hexadecimal - 16":
try {
answerLabel.Text = Convert.ToString(Convert.ToInt32(genTextbox.Text, fromBase), 16).ToUpper();
} catch (Exception) {
Program.showError("error while converting base of generated number.");
} break;
default:
Program.showError("error while converting base of generated number.");
break;
}
timer1.Enabled = true;
} else Program.showError("generate a number first.");
}

public const int WM_NCLBUTTONDOWN = 0xA1;
Expand All @@ -150,12 +159,14 @@ private void FormMove(object sender, MouseEventArgs e) {
}

private void answerLabel_Click(object sender, EventArgs e) {
Clipboard.SetText(answerLabel.Text);
MessageBox.Show("answer copied!", Program.msgTitle);
if (hasFirstGenerated) {
Clipboard.SetText(answerLabel.Text);
Program.showError("answer copied!");
} else Program.showError("nothing to copy. generate a number first.");
}

private void label6_Click(object sender, EventArgs e) {
if (MessageBox.Show("This is version "+Program.appVersion+".\nDo you want to check for newer versions?", Program.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) {
if (MessageBox.Show("This is version "+Program.appVersion+"\nDo you want to check for newer versions?", Program.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) {
System.Diagnostics.Process.Start("https://github.com/alialmasi/radixconvertpractice/releases/latest/");
}
}
Expand Down
Loading

0 comments on commit 7cce954

Please sign in to comment.