Dear All,
Is it possible to make a masked text box for hexadecimal. It means that it is between 0 - 9 and A - F. How also to limit/set the length of char to put inside a textbox. For example there are a trackbar with numbers, if we selct 17, so only 17 chars will be inside the textbox.
The end result will be a hexadecimal text box with user input length.
Thank you all :) have a nice day!
E

2 answers
There isn't in fact a standard mask for hexadecimal characters.
You could write your own MaskedTextProvider to limit input to characters in the hex range but this would be a lot of work to even figure out what to do as I couldn't find a single example when I googled it!
A much better idea is to set the MaskedTextBox's AsciiOnly property to true and then handle its KeyPress event as follows:
You'll notice that, if the user enters lower case 'a' to 'f', then the code automatically capitalizes them to keep things tidy. It also dynamically restricts the length of the input to the value of the trackbar.
If you want to truncate the characters in the MaskedTextBox when the trackbar's value is reduced, then you'll also need to handle the latter's ValueChanged event:
answered 3 months ago by:
12813
396
Great Solution, I luvd that u covered that part of IF trackbar's value changed. But I was wondering that as Erya said... if the value of the trackbar is 17 then the Max limit of text should be 17 chars. Just think if the user is too slow to type 17 chars? Then at every keystroke (ValueChanged)... maskedTextBox1_KeyPress is going to start it's work. Is it a good practise?
12813
Well, it's an unusual requirement to have the maximum length of the textbox set dynamically but you can only really enforce it at keypress level - if the textbox already contains the maximum number of characters, then the keystroke is 'swallowed' by setting e.Handled to true and the method then returns. The whole method should execute in a few milliseconds so no matter how fast you can type, there should be no noticeable lag.
I don't see why you couldn't. Is this a WebForm or a WinForm?
You should be able to dynamically adjust the max length of the characters in the text box, however, you will have to do error checking so if you go from 15 characters to 10 characters, the last 5 are truncated.
Then there should also be a way to limit your input to 0-9, A-F.
answered 3 months ago by:
0
262
Monte, Thanks for your reply. It is not difficult to mask them by putting an event inside the textbox when will trigger when somebody change the text. So I can limit the length and the 0-9 and A-F. But that is not the point of my question. The point is with the *maskedtextbox* from the toolbox, is it possible for us to mask the hexadecimal and the length of the message from *maskedtextbox* properties? It can mask numbers and chars. I suppose there is a way also to mask the hexadecimal and the length. Thanks