Antone.evans
Member
I'm sure this gets asked a lot, but I can't seem to find an answer for it. I want to have my Form2 change a variable in Form1.
thanks,
Antone
thanks,
Antone
If you can explain more about the program flow perhaps we can give better and more relevant advice. For example in a dialog scenario the parent would retrieve data from the child when dialog returns. Normally independent classes would define events and pass information over event parameters, the parent that created the child may subscribe to this event and would get the information whenever the child raises the event. The parent may also pass its own reference to the child, which the child later can use (of course not necessary for default form instances).Plus I'm not passing the value to the child, but to the parent. So I'm not sure how to pass to the parent with a method yet. :/
Public Class Form1
Public Shared userLabel As Label
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
userLabel = lblUsr
lblUsr.Text = "General User"
If lblUsr.Text <> "Admin" Then
BindingNavigatorDeleteItem.Enabled = False
End If
End Sub
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim fLogin As New Form2
fLogin.ShowDialog()
fLogin = Nothing
End Sub
Private Sub btnLogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogout.Click
lblUsr.Text = "General User"
BindingNavigatorDeleteItem.Enabled = False
End Sub
End Class
Public Class Form2
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim logIn As String
logIn = Form1.lblUsr.Text
If txtPassword.Text <> "password" Then
MessageBox.Show("Error: Incorrect Password")
Else
If logIn = "Admin" Then
MessageBox.Show("Error: You are already logged in.")
Else
Form1.lblUsr.Text = "Admin"
Form1.BindingNavigatorDeleteItem.Enabled = True
Me.Close()
End If
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class