Question How to take a value form one form to another from

tashiduks

Member
Joined
Apr 19, 2010
Messages
22
Programming Experience
Beginner
Hi,

I have a Two Forms Created under one Class Library. My Project Looks Like that:

MyProjectClass (class Library)
- frmMain.vb
- frmLogin.vb
- Class1.vb

Now when i run first it loads the "frmLogin". After typing valid User Name and Password, it opens "frmMain". Till here its fine.

Now the problem is: when frmMain opens, the txtUserName.text value of frmLogin should display in frmMain Statusbar which is not happening. I have following Code:

frmLogin
VB.NET:
Private Sub btnOK_Click(sender As Object, e As System.EventArgs) Handles btnOK.Click
dim fMain as new frmMain
 If Me.txtUserName.Text.Trim = "admin" And Me.txtPassword.Text.Trim = "123" Then
                Me.Hide()
                fMain.showdialog()
               me.txtUserName.text = fMain.usernamestatusbar.text 
else
           MessageBox.Show("Invalid User Name or Password! Please try again. ", "Login Failed",  MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.txtUserName.Focus()
                Me.txtPassword.Text = ""
End If
End Sub

Can anyone tell me why its not working? I am using VB.NET 2010 (VB Language)

Thanks
 
That code is poorly constructed I'm afraid. It should be completely reconstructed.

For one thing, you're never passing any data to frmMain. You have code to get data from it, but that code is executed after frmMain closes.

Check out this link for an example of how to use a login form properly:

WinForms Login

Follow the Blog link in my signature below and check out my posts on Data Among Multiple Forms to learn how to move your data around. Be sure to read all three parts.
 
Back
Top