In Windows Form Application concept of Session is not available.
Please refer the below code for verification.
In Form1 i am having two TextBox for UserName and Password and a Button to Login. I am assigning the UserName TextBox value to static variable after successful authentication.
C#
Form1.cs
private void btnLogin_Click(object sender, EventArgs e)
{
//After successful verification
Class1.userName = this.txtUserName.Text;
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
In Form2 load event i am just displaying the UserName in Label.
private void Form2_Load(object sender, EventArgs e)
{
this.lblUserInfoName.Text = string.Format("Welcome {0}", Class1.userName);
}
This is my static class
public static class Class1
{
public static string userName;
}
VB.Net
Form1.vb
Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs)
Class1.userName = Me.txtUserName.Text
Dim f2 As Form2 = New Form2()
f2.Show()
Me.Hide()
End Sub
In Form2 load event i am just displaying the UserName in Label.
Private Sub Form2_Load(ByVal sender As Object, ByVal e As EventArgs)
Me.lblUserInfoName.Text = String.Format("Welcome {0}", Class1.userName)
End Sub
This is my static class
Module Class1
Public Shared userName As String
End Module