|
-
Jul 8th, 2010, 07:01 AM
#1
Thread Starter
Hyperactive Member
When textbox has 10 characters button1 click
Hi!
I'm trying to find out how to automaticly click button1 when textbox1 has 10 characters? Is this even possible?
Thank you!
Last edited by fenhopi; Jul 8th, 2010 at 07:05 AM.
Reason: Spelling mistake
-
Jul 8th, 2010, 07:16 AM
#2
Re: When textbox has 10 characters button1 click
I believe you could use the TextChanged event of your text box. Each time the content of your text box is changed the event is called. Then you check if your textbox length is 10 and call the method you want if it is. I'll run a quick test and let you know if it works.
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Jul 8th, 2010, 07:22 AM
#3
Thread Starter
Hyperactive Member
Re: When textbox has 10 characters button1 click
Thanks for your time!
I tried this:
Code:
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.SelectionLength = "10" Then
Button1.Click()
End If
End Sub
But it didn't work..
-
Jul 8th, 2010, 07:23 AM
#4
Re: When textbox has 10 characters button1 click
Yeah it does work but you need to call Button1_Click instead of Button1.Click()
vb.net Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show("Button1 has been clicked!") End Sub Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged If TextBox1.Text.Length >= 10 Then Button1_Click(Button1, Nothing) End If End Sub End Class
Edit : Note that I used ">=" in case you use copy/paste to paste text in your textbox. Pasting only calls TextChanged once, so if you paste more than 10 character using "=10" will return false.
Last edited by stlaural; Jul 8th, 2010 at 07:29 AM.
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Jul 8th, 2010, 08:25 AM
#5
Re: When textbox has 10 characters button1 click
Syntax error...
If TextBox1.SelectionLength = "10"
Code:
If TextBox1.SelectionLength = 10
The rest is on stlaural code in the previous post
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jul 8th, 2010, 09:09 AM
#6
Re: When textbox has 10 characters button1 click
stlaural, you could just do Button1.PerformClick() or if you prefer calling the method directly pass it an EventArgs.Empty instead of Nothing.
Code:
1.
Public Class Form1
2.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
3.
MessageBox.Show("Button1 has been clicked!")
4.
End Sub
5.
6.
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
7.
If TextBox1.Text.Length >= 10 Then
Button1.PerformClick()
'Or:
Button1_Click(Button1, EventArgs.Empty)
9.
End If
10.
End Sub
11.
End Class
-
Jul 8th, 2010, 09:26 AM
#7
Thread Starter
Hyperactive Member
Re: When textbox has 10 characters button1 click
Thanks for the help guys! I got it now.
-
Jul 8th, 2010, 09:27 AM
#8
Re: When textbox has 10 characters button1 click
 Originally Posted by JuggaloBrotha
stlaural, you could just do Button1.PerformClick() or if you prefer calling the method directly pass it an EventArgs.Empty instead of Nothing.
Code:
1.
Public Class Form1
2.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
3.
MessageBox.Show("Button1 has been clicked!")
4.
End Sub
5.
6.
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
7.
If TextBox1.Text.Length >= 10 Then
Button1.PerformClick()
'Or:
Button1_Click(Button1, EventArgs.Empty)
9.
End If
10.
End Sub
11.
End Class
Yeah, that would be cleaner. I tested quite fast as I'm at work 
thanks JuggaloBrotha
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
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
|