06-30-2009 09:31 AM
I have a database application in that all the textboxes have a limit on the bytes user can write into. I'm thinking whether we can have a way to limit the number of bytes a user can enter into a textbox. I haven't found any property or method that can serve the purpose. Any one can provide some advices?
Thanks and best regards,
Guangde Wang
Solved! Go to Solution.
06-30-2009 09:34 AM
You can try it with the string control set to update while typing and then disable it from a 'calue change' event when it reaches the maximum length
06-30-2009 09:34 AM
Guangde,
you have to read the string, check it's size and limit it if necessary. You can use an event structure to read the string at each key pressed (key down of string control) and then decide if to discard either the first or the last character....
hope this helps,
Norbert
06-30-2009 10:12 AM
Thank you for responding to my post. After I clicked Solution and tried to play it further, I got another question.
In your example, you have the textbox disabled if the byte count is over the limit. It worked okay that way. But when I tried to changed the Disabled property to Blinking, it behaved differently. With Disabled, it counts the bytes while typing. But after I changed it to Blinking, I have to move the focus away from the control textbox then it can recognize it's over the limit. Do you have any explanation?
Guangde
06-30-2009 11:12 AM
06-30-2009 11:43 AM
That's something I feel don't understand. In the original example, we don't have to have the focus away from the textbox. The program knows it's over limit while typing, but I don't know why in this setup, it will not blink.
Guangde
06-30-2009 12:06 PM
I don't think it has anything to do with the event structure or the comparison. Just that the text box doesn't blink when the cursor is inside of it.
Type it a bunch of characters. Leave. It blinks. Click back in it and don't type anything. It stops blinking. Click out, it blinks again. It is just the nature of the blinking property. I don't think it is a bad thing. I think it would be annoying to have a control blinking at you while typing in it.
An alternative might be to set the color of the text box to something else when you are over the limit on characters. Set it back to white when you are okay.
06-30-2009 12:21 PM
I realized that it's the nature of the Blinking property. I made it into a color change and it worked beautifully.
Thanks for your help.
Guangde