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
How do I make this work, Private Sub TextBox1_TextChanged(ByVal sender As System.Obje
Collapse
X
-
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
-
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
-
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
Comment
Comment