How do I make this work, Private Sub TextBox1_TextChanged(ByVal sender As System.Obje

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dixie
    New Member
    • Mar 2014
    • 1

    How do I make this work, Private Sub TextBox1_TextChanged(ByVal sender As System.Obje

    How do I make this work for VB- Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles NameBox.TextCha nged
  • mcupito
    Contributor
    • Aug 2013
    • 294

    #2
    Well, what do you mean 'work' ? What's wrong with it? It's a method that is being called when the Text is changed inside TextBox1.

    Comment

    • redz
      New Member
      • Aug 2013
      • 12

      #3
      this method will triggered in when you type or anything you want to do with your textbox..ontext change then ?????? for example:
      you type this code in your OnTextChanged.. ...
      text1.text="sam ple"
      when you pressed any key on the keyboard it will show a "sample" always...
      Hope this will help you out....

      Comment

      • SebastYin
        New Member
        • Mar 2014
        • 1

        #4
        Very vague question, but I will give you an example of how it would work.

        Code:
        'Button Changes Textbox1's Text.
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                TextBox1.Text = "New Text"
            End Sub
        'Messagebox displayed to show Textbox1's Text.
            Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
                MsgBox("Text of TextBox1 has changed to: " & TextBox1.Text)
        
        End Sub

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          If the TextBox is dynamically added, you need to declare it with events and use the AddHandler method to link the TextChanged event to the method that handles it.

          For example (The following code is NOT tested and is only meant as a guideline because I don't know what type of project you are working with):
          Code:
          Private WithEvents TextBox1 As TextBox
          
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                 If Not Me.Controls.Contains(TextBox1) Then
                    AddHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
                    Me.Controls.Add(TextBox1)
                 End If
          End Sub
          Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                  TextBox1.Text = "New Text"
          End Sub
          
          Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) 
                  MsgBox("Text of TextBox1 has changed to: " & TextBox1.Text)
          End Sub
          -Frinny

          Comment

          Working...