/// <summary> /// update bit lables with address value /// </summary> private void UpdateAddress() { for (byte i = 0; i < 8; i++) { byte v = ByteLib.GetBit(mAddr8Bits, i); BitLabelArray[i].Text = (v == 1) ? "1" : "0"; if (v == 1) { BitLabelArray[i].BackColor = Color.LightGreen; } else { BitLabelArray[i].BackColor = Color.White; } } //update read/write information byte rwBit = ByteLib.GetBit(mAddr8Bits, 0); if (rwBit == 0) { lbRW.Text = "Write"; lbRW.BackColor = Color.Yellow; lb8BitValue.Text = string.Format("W: {0} - 0x{0:X2}", mAddr8Bits); } else { lbRW.Text = "Read"; lbRW.BackColor = Color.LightGreen; lb8BitValue.Text = string.Format("R: {0} - 0x{0:X2} ", mAddr8Bits); } SetAddress((byte)(mAddr8Bits >> 1)); }
/// <summary> /// handle click event on bit label, will toggle the bit value /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void a7_Click(object sender, EventArgs e) { Label l = (Label)sender; byte pos = byte.Parse((string)l.Tag); byte bitV = ByteLib.GetBit(mAddr8Bits, pos); bitV = (byte)((bitV == 0) ? 1 : 0); mAddr8Bits = ByteLib.SetBit(mAddr8Bits, pos, bitV); UpdateAddress(); }
private void B7_Click(object sender, EventArgs e) { Label l = (Label)sender; byte pos = byte.Parse((string)l.Tag); byte bitV = ByteLib.GetBit(mValue, pos); bitV = (byte)((bitV == 0) ? 1 : 0); mValue = ByteLib.SetBit(mValue, pos, bitV); UpdateByteValue(); }
/// <summary> /// update bit lables with address value /// </summary> private void UpdateByteValue() { for (byte i = 0; i < 8; i++) { byte v = ByteLib.GetBit(mValue, i); BitLabelArray[i].Text = (v == 1) ? "1" : "0"; if (v == 1) { BitLabelArray[i].BackColor = Color.LightGreen; } else { BitLabelArray[i].BackColor = Color.White; } } txtDec.Text = string.Format("{0}", mValue); txtHex.Text = string.Format("{0:X}", mValue); if (OnValueChange != null && TriggerEvent) { OnValueChange(this, mValue, mID); } }