From 7cce954359123c5511fa62de353bfd37a2dd9412 Mon Sep 17 00:00:00 2001 From: Ali Almasi Date: Mon, 29 Apr 2024 00:01:21 +0330 Subject: [PATCH] Version 2.2 - minor bug fix --- RadixConvertPractice.v11.suo | Bin 54784 -> 57856 bytes RadixConvertPractice/Form1.Designer.cs | 32 +++-- RadixConvertPractice/Form1.cs | 133 ++++++++++-------- RadixConvertPractice/Program.cs | 25 ++-- .../Properties/AssemblyInfo.cs | 4 +- 5 files changed, 109 insertions(+), 85 deletions(-) diff --git a/RadixConvertPractice.v11.suo b/RadixConvertPractice.v11.suo index 9e768f139e4c95c4c860598018f0eb8330ef5381..8167481dddd50e78ab857cc75c035fcea4d387d9 100644 GIT binary patch delta 2092 zcmdUvZ%kWN6u{qoZK1$>^tE)9l``5Qr9*JEw4;0=yxGpdKniYPOy+FIpTYb?vQZtv zq>FzxBhk_Gh4}}U5*O!~VZ3OJ@}UJYh8odCjG5x*{NM)?GZQf31JrX%JG*FNjK;*< z{Cdwh_uO;tJ@>vFoR9@SmYu06V3|Y{7=}ZU>Kn0Gj9O*jm*-#hjgk=CNO&-@g&AM? zj{N-2*=xiB0d|4QMkgbJ{xLY2cNg@@nz;frq@@`7)2PtUwB-Yl>$d1nqAm*LafHs_ z7-`XwT+EnLphpv318oMBX+$-Wj%=lC8u5ujGb%1*(+%_AFdM~PXt)<~BOYWoav!n> zsYB|Ky+{Mnh}@4fAzp-L1hFWO9NtV}HFcx)2trdliv43q2J!^bi)1Ane=pDE*T?>D zd0-`7Ta%B`)-g+R*EC}$+Gx*XPYXt6IrcPrs^9;kW_0zmX4%P_WeVhZ;4^iSmHUQ- zQnY*)W;HhG%igb~myu44->sF3W{xVkDMke?1OxpluQKP4=Czyw@`4o5?juTN>L{(? z1gx1(aVC^#2nr0#%j9uk+B{iyATe?<#lxSF+p+IJI*~2}MvFWqIiWxb`aYhAWjIBE^sBN7N)pC-`&F@yPGF8)Ydx&?6_DB zZq$w&H3$F28&mX`UjxHPv073Z7U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Uj z>y5>?XyB@Oli%W3gn|5eL8Fo87x^gYabmg|lKwJre;0U7PLa04RURCrv+s|0^ zGv~S<)tu+0(FK2K&!zoe2D&F+elKvegA}NLU01_whj8A*h*uG>L9w;Mc&y^f{2vH( Bf0zIO diff --git a/RadixConvertPractice/Form1.Designer.cs b/RadixConvertPractice/Form1.Designer.cs index c51c163..11cbc15 100644 --- a/RadixConvertPractice/Form1.Designer.cs +++ b/RadixConvertPractice/Form1.Designer.cs @@ -63,17 +63,19 @@ private void InitializeComponent() { // // baseList // + this.baseList.BackColor = System.Drawing.SystemColors.WindowText; this.baseList.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.baseList.Font = new System.Drawing.Font("Arial", 11.25F); + this.baseList.ForeColor = System.Drawing.SystemColors.Window; this.baseList.FormattingEnabled = true; this.baseList.Items.AddRange(new object[] { "Binary - 2", "Octal - 8", "Decimal - 10", "Hexadecimal - 16"}); - this.baseList.Location = new System.Drawing.Point(185, 65); + this.baseList.Location = new System.Drawing.Point(174, 65); this.baseList.Name = "baseList"; - this.baseList.Size = new System.Drawing.Size(130, 25); + this.baseList.Size = new System.Drawing.Size(141, 25); this.baseList.TabIndex = 1; this.baseList.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged); // @@ -83,16 +85,16 @@ private void InitializeComponent() { this.label1.Font = new System.Drawing.Font("Arial", 11.25F); this.label1.Location = new System.Drawing.Point(25, 68); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(155, 17); + this.label1.Size = new System.Drawing.Size(143, 17); this.label1.TabIndex = 2; - this.label1.Text = "Select a number base:"; + this.label1.Text = "Select number base:"; this.label1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.FormMove); // // answerButton // this.answerButton.Cursor = System.Windows.Forms.Cursors.Hand; this.answerButton.FlatAppearance.BorderColor = System.Drawing.SystemColors.ControlDark; - this.answerButton.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.answerButton.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Black; this.answerButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.answerButton.Font = new System.Drawing.Font("Arial", 11.25F); this.answerButton.Location = new System.Drawing.Point(28, 283); @@ -107,7 +109,7 @@ private void InitializeComponent() { // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Arial", 11.25F); - this.label2.Location = new System.Drawing.Point(36, 118); + this.label2.Location = new System.Drawing.Point(25, 118); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(144, 17); this.label2.TabIndex = 5; @@ -116,16 +118,20 @@ private void InitializeComponent() { // // lenTxb // + this.lenTxb.BackColor = System.Drawing.SystemColors.WindowText; this.lenTxb.Font = new System.Drawing.Font("Arial", 11.25F); - this.lenTxb.Location = new System.Drawing.Point(185, 115); + this.lenTxb.ForeColor = System.Drawing.SystemColors.Window; + this.lenTxb.Location = new System.Drawing.Point(174, 115); this.lenTxb.Name = "lenTxb"; - this.lenTxb.Size = new System.Drawing.Size(130, 25); + this.lenTxb.Size = new System.Drawing.Size(141, 25); this.lenTxb.TabIndex = 6; // // genTextbox // + this.genTextbox.BackColor = System.Drawing.Color.Black; this.genTextbox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.genTextbox.Font = new System.Drawing.Font("Arial", 11.25F); + this.genTextbox.ForeColor = System.Drawing.SystemColors.Window; this.genTextbox.ImeMode = System.Windows.Forms.ImeMode.Off; this.genTextbox.Location = new System.Drawing.Point(27, 203); this.genTextbox.Name = "genTextbox"; @@ -155,7 +161,7 @@ private void InitializeComponent() { // this.genButton.Cursor = System.Windows.Forms.Cursors.Hand; this.genButton.FlatAppearance.BorderColor = System.Drawing.SystemColors.ControlDark; - this.genButton.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.genButton.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Black; this.genButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.genButton.Font = new System.Drawing.Font("Arial", 11.25F); this.genButton.Location = new System.Drawing.Point(28, 167); @@ -170,7 +176,7 @@ private void InitializeComponent() { // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Arial", 11.25F); - this.label3.Location = new System.Drawing.Point(39, 253); + this.label3.Location = new System.Drawing.Point(25, 253); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(141, 17); this.label3.TabIndex = 11; @@ -179,17 +185,19 @@ private void InitializeComponent() { // // answerBase // + this.answerBase.BackColor = System.Drawing.SystemColors.WindowText; this.answerBase.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.answerBase.Font = new System.Drawing.Font("Arial", 11.25F); + this.answerBase.ForeColor = System.Drawing.SystemColors.Window; this.answerBase.FormattingEnabled = true; this.answerBase.Items.AddRange(new object[] { "Binary - 2", "Octal - 8", "Decimal - 10", "Hexadecimal - 16"}); - this.answerBase.Location = new System.Drawing.Point(186, 250); + this.answerBase.Location = new System.Drawing.Point(174, 250); this.answerBase.Name = "answerBase"; - this.answerBase.Size = new System.Drawing.Size(129, 25); + this.answerBase.Size = new System.Drawing.Size(141, 25); this.answerBase.TabIndex = 10; // // timer1 diff --git a/RadixConvertPractice/Form1.cs b/RadixConvertPractice/Form1.cs index 7c57a99..9246031 100644 --- a/RadixConvertPractice/Form1.cs +++ b/RadixConvertPractice/Form1.cs @@ -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(); } @@ -20,6 +21,7 @@ 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(); @@ -27,9 +29,10 @@ private void Form1_Load(object sender, EventArgs e) { } 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 { @@ -37,7 +40,7 @@ private void genButton_Click(object sender, EventArgs e) { 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": @@ -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; } } @@ -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; @@ -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/"); } } diff --git a/RadixConvertPractice/Program.cs b/RadixConvertPractice/Program.cs index c7c0879..a5e3bab 100644 --- a/RadixConvertPractice/Program.cs +++ b/RadixConvertPractice/Program.cs @@ -14,7 +14,7 @@ static void Main() { bool createdNew; mutex = new Mutex(true, Application.ProductName, out createdNew); if (!createdNew) { - MessageBox.Show("Only one instance of this app is allowed.", msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + showError("Only one instance of this app is allowed."); return; } Application.EnableVisualStyles(); @@ -22,6 +22,11 @@ static void Main() { Application.Run(new Form1()); } + public static void showError(string errorText = "Runtime error!\nInform the developer by creating an issue on GitHub.", bool issues = false) { + MessageBox.Show(errorText, msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + if (issues) System.Diagnostics.Process.Start("https://github.com/alialmasi/radixconvertpractice/issues"); + } + public static string generateBinary(int length = 0) { if (length > 0) { try { @@ -35,11 +40,11 @@ public static string generateBinary(int length = 0) { for (int i = 0; i < x.Length; i++) output += x[i].ToString(); return output.TrimStart('0'); } catch (Exception ex) { - MessageBox.Show("error when generating binary number:\n\n" + ex.Message, msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + showError("error when generating binary number:\n\n" + ex.Message); return "error"; } } else { - MessageBox.Show("please enter a valid number length.", msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + showError("please enter a valid number length."); return "error"; } } @@ -57,11 +62,11 @@ public static string generateOctal(int length = 0) { for (int i = 0; i < x.Length; i++) output += x[i].ToString(); return output.TrimStart('0'); } catch (Exception ex) { - MessageBox.Show("error when generating octal number:\n\n" + ex.Message, msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + showError("error when generating octal number:\n\n" + ex.Message); return "error"; } } else { - MessageBox.Show("please enter a valid number length.", msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + showError("please enter a valid number length."); return "error"; } } @@ -79,11 +84,11 @@ public static string generateDecimal(int length = 0) { for (int i = 0; i < x.Length; i++) output += x[i].ToString(); return output.TrimStart('0'); } catch (Exception ex) { - MessageBox.Show("error when generating decimal number:\n\n" + ex.Message, msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + showError("error when generating decimal number:\n\n" + ex.Message); return "error"; } } else { - MessageBox.Show("please enter a valid number length.", msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + showError("please enter a valid number length."); return "error"; } } @@ -97,13 +102,13 @@ public static string generateHexadecimal(int length = 0) { string result = String.Concat(buffer.Select(x => x.ToString("X2")).ToArray()); if (length % 2 == 0) return result; - return result + r.Next(16).ToString("X"); + return result + r.Next(16).ToString("X").TrimStart('0'); } catch (Exception ex) { - MessageBox.Show("error when generating hexadecimal number:\n\n" + ex.Message, msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + showError("error when generating hexadecimal number:\n\n" + ex.Message); return "error"; } } else { - MessageBox.Show("please enter a valid number length.", msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + showError("please enter a valid number length."); return "error"; } } diff --git a/RadixConvertPractice/Properties/AssemblyInfo.cs b/RadixConvertPractice/Properties/AssemblyInfo.cs index 97fc0b9..ff75c5d 100644 --- a/RadixConvertPractice/Properties/AssemblyInfo.cs +++ b/RadixConvertPractice/Properties/AssemblyInfo.cs @@ -33,6 +33,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.1.0.0")] -[assembly: AssemblyFileVersion("2.1.0.0")] +[assembly: AssemblyVersion("2.2.0.0")] +[assembly: AssemblyFileVersion("2.2.0.0")] [assembly: NeutralResourcesLanguageAttribute("en")]