1,105,644 Community Members

Textbox.text to Label.text

Member Avatar
Neyney1975
Newbie Poster
2 posts since Aug 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello Everyone,

I'm extremely new to programming in Visual Basic and I have a programming exercise which I need help with.

I have a textbox and a label on a form. The objective of the program is for the label to update with any text typed into the textbox as it is typed. So without buttons or clicks.

My teacher has said that it is a complicated thing but that it can be solved quite easily. I can't imagine he wants wads of code from a firsttimer :) Am I correct in that it has something to do with databinding? Any thoughts on how I can solve this one?

Thanks in advance for any help!

Member Avatar
DM Galaxy
Junior Poster in Training
65 posts since Aug 2013
Reputation Points: -6 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 5 [?]
 
0
 

Add a timer, textbox, label...
Make Label dock on the Top
Make the TextBox Dock on Bottom
Change timer Properties to Enable = True
Timer Interval = 1 or 10 or 100 or 1000 (1000 = 1 sec, 1 will be super fast)

Timer Code:

label1.Text = TextBox1.Text

This code means: Label 1 will be the same as textBox1.Character.
I think you got what you mean?

Member Avatar
Reverend Jim
Noli mentula
5,444 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

It's not a complicated thing and it does not require databinding. If your teacher says it is a complicated thing then I suggest you take everything he/she says with a grain of salt.

Because this is an assignment I will not give you the code but here is a hint. Every time someone makes a change to the text in the textbox you want to change the label to be the same as the textbox. So you have an event that you want to respond to. It only requires you to write one line of code. Let me know if that helps.

Member Avatar
Neyney1975
Newbie Poster
2 posts since Aug 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I got it.

Public Class Form1

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    Label1.Text = TextBox1.Text
End Sub

End Class

This worked. I actually tried a variation of this last night before I decided to ask for help and I see now that I had it the wrong way around which is why it wasn't working.

Thanks again.

Question Answered as of 7 Months Ago by Reverend Jim and DM Galaxy
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article