Results 1 to 8 of 8

Thread: When textbox has 10 characters button1 click

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    England
    Posts
    270

    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

  2. #2
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    England
    Posts
    270

    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..

  4. #4
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    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:
    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
    8.             Button1_Click(Button1, Nothing)
    9.         End If
    10.     End Sub
    11. 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

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    England
    Posts
    270

    Re: When textbox has 10 characters button1 click

    Thanks for the help guys! I got it now.

  8. #8
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: When textbox has 10 characters button1 click

    Quote Originally Posted by JuggaloBrotha View Post
    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
  •  



Click Here to Expand Forum to Full Width