|
-
May 23rd, 2009, 08:14 PM
#1
Thread Starter
Lively Member
[RESOLVED] How to set Minimum character[HELP]
How would i set a minimum number of characters in textbox1 for a button to work. and if the person does not enter the minimum number of characters, a messagebox pops up sayin something like "need at least 5 characters!" Thanks
-
May 23rd, 2009, 08:17 PM
#2
Re: How to set Minimum character[HELP]
Set the button initially to disabled and try this:
vb.net Code:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Me.Button1.Enabled = (Me.TextBox1.Text.Length > 5) End Sub
A MessageBox coming up would be really annoying I think from a UI point of view. That said, you could make it so when they click the button it checks the textbox length and then shows the MessageBox.
-
May 23rd, 2009, 08:22 PM
#3
Thread Starter
Lively Member
Re: How to set Minimum character[HELP]
Thx so much it worked !!! +rep
-
May 23rd, 2009, 08:25 PM
#4
Addicted Member
Re: How to set Minimum character[HELP]
 Originally Posted by x DeaDLy
How would i set a minimum number of characters in textbox1 for a button to work. and if the person does not enter the minimum number of characters, a messagebox pops up sayin something like "need at least 5 characters!" Thanks
 Originally Posted by ForumAccount
Set the button initially to disabled and try this:
vb.net Code:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Me.Button1.Enabled = (Me.TextBox1.Text.Length > 5)
End Sub
A MessageBox coming up would be really annoying I think from a UI point of view. That said, you could make it so when they click the button it checks the textbox length and then shows the MessageBox.
I agree with ForumAccount. The app that I'm currently working on has many of these cases where controls switch from Enabled to Disabled. I think it looks smart.
PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX
"Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54
-
May 23rd, 2009, 09:07 PM
#5
Hyperactive Member
Re: How to set Minimum character[HELP]
 Originally Posted by x DeaDLy
Thx so much it worked !!! +rep
Or
Code:
if len(textbox1.text) < 5 Then
Button1.Enabled=false
Else
Button1.Enabled=True
End If
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
|