Ram Poke - better input validation on text boxes

This commit is contained in:
andres.delikat 2011-02-24 13:46:49 +00:00
parent de39858cb9
commit 98643b0599
3 changed files with 43 additions and 1 deletions

View File

@ -71,6 +71,7 @@
this.AddressBox.TabIndex = 2;
this.AddressBox.Text = "0000";
this.AddressBox.Leave += new System.EventHandler(this.AddressBox_Leave);
this.AddressBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.AddressBox_KeyPress);
//
// DataTypeGroupBox
//
@ -241,6 +242,7 @@
this.ValueBox.TabIndex = 11;
this.ValueBox.Text = "0000";
this.ValueBox.Leave += new System.EventHandler(this.ValueBox_Leave);
this.ValueBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ValueBox_KeyPress);
//
// RamPoke
//

View File

@ -195,5 +195,46 @@ namespace BizHawk.MultiClient
t.Show("Must be a valid unsigned decimal value", ValueBox, 5000);
}
}
private asigned GetDataType()
{
if (SignedRadio.Checked)
return asigned.UNSIGNED;
if (UnsignedRadio.Checked)
return asigned.SIGNED;
if (HexRadio.Checked)
return asigned.HEX;
return asigned.UNSIGNED; //Just in case
}
private void AddressBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b') return;
if (!InputValidate.IsValidHexNumber(e.KeyChar))
e.Handled = true;
}
private void ValueBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b') return;
switch (GetDataType())
{
case asigned.UNSIGNED:
if (!InputValidate.IsValidUnsignedNumber(e.KeyChar))
e.Handled = true;
break;
case asigned.SIGNED:
if (!InputValidate.IsValidSignedNumber(e.KeyChar))
e.Handled = true;
break;
case asigned.HEX:
if (!InputValidate.IsValidHexNumber(e.KeyChar))
e.Handled = true;
break;
}
}
}
}

View File

@ -1550,7 +1550,6 @@ namespace BizHawk.MultiClient
e.Handled = true;
break;
}
}
private void SpecificAddressBox_KeyPress(object sender, KeyPressEventArgs e)