Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Text Boxes

7 views
Skip to first unread message

Richy Rich

unread,
Apr 10, 2003, 10:40:52 AM4/10/03
to
Hi,

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!

Mikael Jansson

unread,
Apr 10, 2003, 12:27:59 PM4/10/03
to
Hi,

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...

Richy Rich

unread,
Apr 10, 2003, 2:52:24 PM4/10/03
to

thanks, I'll give it a try :)

0 new messages