[RESOLVED] Trigger TextBox When Form Opens???
I am creating a form and I have a label that will display the user's name, but what I need to do it trigger a text box when the application opens that will allow the user to type in their name and then assign that value to the label in my form. How do I trigger the text box and assign the value to my label? My label is named lblStudent. Can anyone help me with this?
Re: Trigger TextBox When Form Opens???
Try this:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Label1.Caption = Text1
End Sub
Re: Trigger TextBox When Form Opens???
When I tried to add this code, both the Label1 and Text1 say they are not declared and there is an error when I try to run the script. I don't have a text box on my form, I just have the label. I need to have a text box trigger when the form opens, like a pop up I guess, and then the user can put in their name and then the value of the text box gets saves to the label (lblStudent). I'm new to this type of coding. Can you be a little more detailed?
Re: Trigger TextBox When Form Opens???
Try adding a TextBox and a Label, both named: Text1 and Label1. To use the code posted in Post #2.
Re: Trigger TextBox When Form Opens???
Quote:
Originally Posted by
twilitegxa
When I tried to add this code, both the Label1 and Text1 say they are not declared and there is an error when I try to run the script. I don't have a text box on my form, I just have the label. I need to have a text box trigger when the form opens, like a pop up I guess, and then the user can put in their name and then the value of the text box gets saves to the label (lblStudent). I'm new to this type of coding. Can you be a little more detailed?
Welcome to the forums...:wave:
I think, InputBox() is really what you want..!
Code:
Private Sub Form_Load()
lblStudent.Caption = InputBox("Enter your name:")
End Sub
...:wave:
Re: Trigger TextBox When Form Opens???
Quote:
Originally Posted by
akhileshbc
Welcome to the forums...:wave:
I think, InputBox() is really what you want..!
Code:
Private Sub Form_Load()
lblStudent.Caption = InputBox("Enter your name:")
End Sub
...:wave:
That sound more like what I am needing, but when I tried your code, I received this error:
Error 1 'Caption' is not a member of 'System.Windows.Forms.Label'.
Can you help? I don't know what to do.
Re: Trigger TextBox When Form Opens???
What kind of Visual Basic or Visual Studio are you using. Because that sounds like a .NET version of Visual Basic!! If I'm not mistaken??? Or your ActiveX control, hasn't been registered, or that you have to add it into your project!!
Re: Trigger TextBox When Form Opens???
Quote:
Originally Posted by
twilitegxa
That sound more like what I am needing, but when I tried your code, I received this error:
Error 1 'Caption' is not a member of 'System.Windows.Forms.Label'.
Can you help? I don't know what to do.
You are not using VB6. In that language, labels have a caption property. In VB.NET, they have a text property, so it would be
Code:
lblStudents.Text = Whatever
Moved To VB.NET
Re: Trigger TextBox When Form Opens???
I think you use vs8
beside in vs8 we dont have any caption for label1 in vs8 it's text
it's the same code that akhileshbc said
1-make a label1
just copy these in your code page
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = InputBox("Enter your name:")
End Sub
End Class
Re: Trigger TextBox When Form Opens???
Quote:
Originally Posted by
akhileshbc
Welcome to the forums...:wave:
I think, InputBox() is really what you want..!
Code:
Private Sub Form_Load()
lblStudent.Caption = InputBox("Enter your name:")
End Sub
...:wave:
i was having same problem
ty for you're help
Re: Trigger TextBox When Form Opens???
Ok how about this
in form1 you make one textbox and in form2 you have your label
in startup first you load form1 and the user type his name and then form2 coming up with the label that have the value of textbox in form1
i think you should try this;)
Re: Trigger TextBox When Form Opens???
Quote:
Originally Posted by
Pc Monk
I think you use vs8
beside in vs8 we dont have any caption for label1 in vs8 it's text
it's the same code that akhileshbc said
1-make a label1
just copy these in your code page
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = InputBox("Enter your name:")
End Sub
End Class
Thank you so much! This example did the trick!