private void CreateHRESULT_Click(object sender, EventArgs e) { LabelError.Text = ""; { CodeTextBox.BackColor = ProfessionalColors.OverflowButtonGradientMiddle; foreach (Control c in groupBox1.Controls) { c.BackColor = ProfessionalColors.OverflowButtonGradientMiddle; } } long hresultcode = 0; //32 bit number UInt16 codeshort = 0; List <int> ilist = new List <int>(32); ilist.Capacity = 32; for (int i = 0; i < 32; i++) { ilist.Add(0); } bool ignorecode = (CodeTextBox.Text != ""); if (ignorecode) { try { codeshort = UInt16.Parse(CodeTextBox.Text); } //Get i16 from CodeTextBox. catch (Exception) { CodeTextBox.BackColor = System.Drawing.Color.Red; } } foreach (Control t in groupBox1.Controls) { if (t.GetType() == CodeTextBox.GetType()) { try { int i = int.Parse(t.Text); if (t.Name.Contains("Bit") && t.Name != "Bits") { int index = 0; if (t.Name.Length == 5) { index = int.Parse(t.Name.Substring(3, 2)) - 1; } if (t.Name.Length == 4) { index = int.Parse(t.Name.Substring(3, 1)) - 1; } if (i == 0) { ilist[index] = 0; } if (i > 0) { ilist[index] = 1; } } else { }; } catch (Exception ex) { t.BackColor = System.Drawing.Color.Red; LabelError.Text += "\nError in bits! (" + t.Name + " not set! Assuming \"0\")"; } } } for (int i = 0; i < 32; i++) { hresultcode = hresultcode | (uint)(ilist[i] << 31 - i); } if (codeshort != 0) { hresultcode = hresultcode & 0xFFFF0000; hresultcode = hresultcode | (long)codeshort; } HRESDec.Text = hresultcode.ToString(); HRESHex.Text = "0x"; HRESHex.Text += hresultcode.ToString("X"); bool error3 = false, error2 = false, error5 = false; if (Bit3.Text == "0") { error3 = true; } if (Bit2.Text == "1" && Bit4.Text == "0") { error2 = true; } if (Bit5.Text == "1") { error5 = true; } if (error2 || error3 || error5) { LabelError.Text += "\nWarning! \nI won't stop you from creating this HRESULT value, but it breaks specification!"; } if (error2) { LabelError.Text += "\n(R bit set, N bit clear) "; } if (error3) { LabelError.Text += "\n(C bit not set! This should be set if this isn't a Microsoft HRESULT.)"; } if (error5) { LabelError.Text += "\n(X bit set! This is reserved, and this could be ignored if there is a reason for setting it.)"; } }