I have created a text box called 'syncByteText' to receive a maximum of
2 characters. The ToUpper option is true so that they are automatically
converted to capitials.
The purpose of the text box is to store a 1 byte hexadecimal number, so
the only valid characters can be from 0 to 9 and A to F.
I have used a keypress handler in VB and it is possible to make it so
that it cannot accept characters that are out of range (i.e. 'K').
I have made a key handler in my C# app (see below). Problem is
ex.KeyChar is read only, so it can be set to zero to delete characters
that are out of range.
Is there a way of setting the text box up to receive a hexidecimal
number only?
Thanks in adv, Richy.
private void SyncByteKeyHandler(object sender, KeyPressEventArgs ex)
{
if( ( ex.KeyChar >= '0' && ex.KeyChar <= '9' ) ||
( ex.KeyChar >= 'A' && ex.KeyChar <= 'F' ) ||
( ex.KeyChar >= 'a' && ex.KeyChar <= 'f' ) )
{
if( SyncByteText.Text.Length > 2 )
{
SyncByteText.Text = ex.KeyChar.ToString();
}
}
else
{
// don't display character - it's not hex :(
}
}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
To prevent the textbox from displaying characters typed just set the Handled
property on the KeyPressEventArgs object to true when you detect an unwanted
character.
...
else
{
// don't display character - it's not hex :(
ex.Handled = true;
}
...
Regards, Mikael
"Richy Rich" <richyri...@yahoo.co.uk> wrote in message
news:e0O5w82$CHA....@TK2MSFTNGP12.phx.gbl...
thanks, I'll give it a try :)