Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
890 views
in Technique[技术] by (71.8m points)

winforms - Session for windows forms application in C#

Is there a session for Windows based applications for C# in order to record the details of log in in and log out for multiple users?

I tried to use declaring static variables, but it is not the same as a session.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no concept of session variables in Windows Forms. You can do:

Create a static class that holds the user name and password and any other variables needed across the application.

In your case it would be something like:

public static class LoginInfo
{
    public static string UserID;
}

Now you can access the UserID simply from anywhere in your code:

MessageBox.Show(LogInfo.UserID);

Or set the values after login like:

LogInfo.UserID = TextBox1.Text;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...