Nick_Net2004 Posted May 11, 2004 Posted May 11, 2004 Ok here's the deal: I create a login form as ShowDialog from the main form. So after the user entered his username & password I want to pass these values to the main form when he hits the ok button of the login form and that form close. Tx in advance Quote
Administrators PlausiblyDamp Posted May 11, 2004 Administrators Posted May 11, 2004 You may want to look here contains a nice tutorial on passing information between forms. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nick_Net2004 Posted May 11, 2004 Author Posted May 11, 2004 Tx a lot it helped me figured out what I wanted to do... For whom who need to do the same thing here how I did it ->Main Form Public Class Form1 Inherits System.Windows.Forms.Form 'Store username and password from login form 'Declare friend so they can be called by other forms Friend username As String Friend password As String Private FormLogin As New Login() Private FormLogout As New Logout(Me) Private FormExit As New _Exit() #Region " Windows Form Designer generated code " 'Allows the user to login Private Sub MenuLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuLogin.Click 'Dim FormLogin As New Login() 'Create the login window so that the user can login the window is modal so he can't access the main form 'while the login form is open FormLogin.ShowDialog() If FormLogin.CmdOk.DialogResult.ToString = "OK" Then 'Store attributed username & password from login form username = FormLogin.TxtUserName.Text password = FormLogin.TxtPassword.Text End If End Sub 'Allows the user to logout Private Sub MenuLoggout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuLoggout.Click 'Dim FormLogout As New Logout(Me) 'Create the logout window so that the user can logout the window is modal so he can't access the main form 'while the logout form is open FormLogout.ShowDialog() End Sub 'Close the application if the user accept Private Sub MenuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuExit.Click 'Dim FormExit As New _Exit() 'Create the exit window so that the user can exit, the window is modal so he can't access the main form 'while the exit form is open FormExit.ShowDialog() If FormExit.CmdOk.DialogResult.ToString = "OK" Then Me.Close() End If End Sub End Class ->login form Public Class Login Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Private Sub CmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdOk.Click 'Set the dialog result so it can be use Me.CmdOk.DialogResult = System.Windows.Forms.DialogResult.OK Me.Close() End Sub Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCancel.Click Me.Close() End Sub End Class ->logout form Public Class Logout Inherits System.Windows.Forms.Form Private callingForm As Form1 #Region " Windows Form Designer generated code " Public Sub New(ByVal newCallingForm As Form1) MyBase.New() InitializeComponent() callingForm = newCallingForm End Sub Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCancel.Click Me.Close() End Sub Private Sub Logout_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'On load fill TxtName with the name of the user currently logged in TxtName.Text = callingForm.username End Sub End Class Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.