Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The behaviou of Textbox and Lablel are different? 1

Status
Not open for further replies.

greathope123

Programmer
Nov 1, 2011
84
GB
Hi,

When start my VB.Net program, the behaviou of Textbox and Lablel are different:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

TextBox2.Text = "222222222222"
Label4.Text = "4444444444444"

End Sub
TextBox2 will show "222222222222" but Label4 wont show anything!

What I am doing wrong?
 
Must be something you are not showing us. This works fine:

Code:
    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged

   TextBox2.Text = "222222222222"
   Label4.Text = "Works for me"

End Sub

Post your code.
 
Oops...it is posted. I can't see why it is not working unless something is changing it after the fact.
 
TysonLPrice,

"Must be something you are not showing us"
Actually, sorry, I forgot to tell you that I have set TextBox1.Text in design time and that is why
TextBox1_TextChanged()
fired when start my VB.Net program.
Your code wont fire when start you VB.Net program unless you set some string to TextBox1.Text in design time or change TextBox1.Text in run time!!
 
I can reproduce that now...beats the crap out of me. I'm playing around with it now.
 
I'm using VS 2010

I've set TextBox in design and left Label blank in design. Copied your code in the TextChanged handler and run the program. The Label is populated as expected.
 
Leaving the label blank seems to be the key. If it is not when the form loads it hits the Lable changed event a second time putting back the original value not what was changed.

Code:
Public Class Form1

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged

        TextBox2.Text = "222222222222"
        Label4.Text = "4444444444444"

    End Sub


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub


    Private Sub Label4_TextChanged(sender As Object, e As EventArgs) Handles Label4.TextChanged
        Debug.Print(Label4.Text)
    End Sub
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top