Sending info from Form1 to Form2
-
frmlogin has txtusername.text and txtpassword.text. I would like to take the text that is put into the txtusername.text and send it over to form2 once I hide frmlogin and show form2. I have tried this and failed. Public user as string user = txtusername.text This does not work when I try to put user into form2. So how would I go about this? Thank You -- modified at 18:26 Monday 6th March, 2006
-
frmlogin has txtusername.text and txtpassword.text. I would like to take the text that is put into the txtusername.text and send it over to form2 once I hide frmlogin and show form2. I have tried this and failed. Public user as string user = txtusername.text This does not work when I try to put user into form2. So how would I go about this? Thank You -- modified at 18:26 Monday 6th March, 2006
Form1 contains: -txtusername -txtpass Form2 contains: -lblUser -lblPass When closeing form1... Dim fr as new Form2 fr.lblUser.text=txtusername.text fr.lblPass.text=txtusername.text fr.showdialog and on Form2 make that labels invisible... Thats all... :-> FeRtoll Software.net -------------------- I fertoll@net.hr I --------------------
-
frmlogin has txtusername.text and txtpassword.text. I would like to take the text that is put into the txtusername.text and send it over to form2 once I hide frmlogin and show form2. I have tried this and failed. Public user as string user = txtusername.text This does not work when I try to put user into form2. So how would I go about this? Thank You -- modified at 18:26 Monday 6th March, 2006
The easy way is to create a public variable on Form2 and pass the txtusername.text to that variable Insert on the top of the class of Form2 Public UserName as String In the frmLogin: Dim SecondForm as new form2 SecondForm.UserName=txtusername.text SecondForm.show me.hide You can also use a property but... Hope it helps
-
frmlogin has txtusername.text and txtpassword.text. I would like to take the text that is put into the txtusername.text and send it over to form2 once I hide frmlogin and show form2. I have tried this and failed. Public user as string user = txtusername.text This does not work when I try to put user into form2. So how would I go about this? Thank You -- modified at 18:26 Monday 6th March, 2006
Hi You can do this in many ways. I will suggest 2 ways. 1. Create property on form2... (Say User) and set that property after initialize form2 class. Set the property value to label on it in the form_load Sample code written on VB 2005 Public Class Form2 'Use property for this Public user As String Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Label1.Text = user End Sub End Class Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim f2 As Form2 = New Form2() f2.user = Me.txtLogin.Text f2.ShowDialog() End Sub End Class 2. Create constructor in Form2 in order to pass string (Public sub New (user as string)) And pass textbox value then you initialize Form2. Set the passed value to label on it in the form_load No sample code .. (i didnot check this should be work) Try those. Guaranteed to work well Regards, chandana
-
frmlogin has txtusername.text and txtpassword.text. I would like to take the text that is put into the txtusername.text and send it over to form2 once I hide frmlogin and show form2. I have tried this and failed. Public user as string user = txtusername.text This does not work when I try to put user into form2. So how would I go about this? Thank You -- modified at 18:26 Monday 6th March, 2006
On form2 I have set Public username as String. On frmlogin this is the code for the ok button when you type in the username and passwoed. If txtpassword.text = frmlogin.tag Then Dim secondforum As New Form2 secondform.username = txtusername.text secondform.show me.hide Else msgbox "Try Again" End If On form2 under Forum Load I have form2.caption = username For some reason the username does not go over to form2. I tried to use F8 to see if the username was being seen in Public username as String but for some reason when in F8 mode it won't skip over to the second form code so I can hover over it with mouse and check. *EDIT* Ok I got it to work not sure what did it though. But aftering changing secondform.username = txtusername.text to secondform.username = me.txtusername.text it worked. And on form2 useing me.caption = username. Thank you for the help! -- modified at 19:05 Monday 6th March, 2006
-
On form2 I have set Public username as String. On frmlogin this is the code for the ok button when you type in the username and passwoed. If txtpassword.text = frmlogin.tag Then Dim secondforum As New Form2 secondform.username = txtusername.text secondform.show me.hide Else msgbox "Try Again" End If On form2 under Forum Load I have form2.caption = username For some reason the username does not go over to form2. I tried to use F8 to see if the username was being seen in Public username as String but for some reason when in F8 mode it won't skip over to the second form code so I can hover over it with mouse and check. *EDIT* Ok I got it to work not sure what did it though. But aftering changing secondform.username = txtusername.text to secondform.username = me.txtusername.text it worked. And on form2 useing me.caption = username. Thank you for the help! -- modified at 19:05 Monday 6th March, 2006
The best way to do this is store the username in a global variable in the login screen. This variable can be accessed throughout the application. With Best Regards, Mayur -- modified at 23:22 Monday 6th March, 2006