I found the solution, below:
Source: link
On the Windows Forms platform, people find it difficult to maintain this type of session with variables and information, however, there is a simple way to record session using the desktop platform without any problem.
Working with Session is simple and smooth. Soon after entering the user and password, the variables need to be filled in and saved in the session for future use or verification.
Using Windows Forms, the first step is to create a public and static type class.
Creating Class
Right-click on your project or inside a UTIL folder, choose Add / New Item ...
Aftergivingthename(Session.system.cs)andclickingtheAddbutton,putthefollowingdata:
Step1:PutthewordPublicStaticatthebeginningoftheclass.
publicstaticclassSessaoSistema{}
Step2:GenerateGetandSetvariableswithintheclass.TheyshouldbestaticwithintheSessionSystemclass.
//usuarioprivatestaticInt32_usuarioId;privatestaticString_nomeUsuario;privatestaticString_emailUsuario;//getesetpublicstaticStringUsuarioId{get{returnSessaoSistema._usuarioId;}set{SessaoSistema._usuarioId=value;}}publicstaticStringNomeUsuario{get{returnSessaoSistema._nomeUsuario;}set{SessaoSistema._nomeUsuario=value;}}publicstaticStringEmailUsuario{get{returnSessaoSistema._emailUsuario;}set{SessaoSistema._emailUsuario=value;}}
UsingSessionClass
Nowontheloginscreen,afterenteringtheusernameandpasswordforthedesktopsystem,fillintheinformationasfollows.
//depoisdologinokSessaoSistema.NomeUsuario=txtNomeUsuario.text;SessaoSistema.UsuarioId=usuarioId;SessaoSistema.EmailUsuario=txtEmail.text;
Anywhereinthesystemyoucanpickupthedatastoredintheuser'sLoginafterjusttypingandSystem.Sessionvariable.Property(forexample:SystemSession.UserName.
Source: link
More information:
link