|
-
Apr 9th, 2006, 05:32 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2.0] Max Length, eh?
Someone help me out here? I can set the max length of a textbox to 8 but when I do something it can still input a number greater than 8 into the textbox. For example, if I push a button it can put 8+ letters or numbers in it. The reason I want this is because I have this code for a DateTimePicker ValueChanged event:
firsthoursbox.Text = Convert.ToString(firstendbox.Value - firststartbox.Value);
And.. When I first click it. It will give something like 00:59:59.8750000
It's kind of annoying.. Someone help me out here? Thanks.
-
Apr 9th, 2006, 06:36 PM
#2
Re: [2.0] Max Length, eh?
As always, the first thing to do is to read the relevant dicumentation. Here's a quote from the help topic for TextBox.MaxLength:
In code, you can set the value of the Text property to a value that has a length greater than the value specified by the MaxLength property. This property only affects text entered into the control at run time.
I imagine that the rationale is that it's your code and if you don't want to put a string longer than eight characters in the text box then you won't. If you don't want that entire string in the text box then either use String.Format to create exactly the string you want or else use String.Substring to remove the characters you don't want.
-
Apr 10th, 2006, 09:42 AM
#3
Hyperactive Member
Re: [RESOLVED] [2.0] Max Length, eh?
Might want to look into a masked textbox with a mask of "########" or something along those lines.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|