To close the logon form and open a new main form after the login form verification is complete. The principle is: create a new form before closing and save it in a form variable. Solution 2 is as follows:
Namespace inventory management
{
Static class Program
{
/// <Summary>
/// ApplicationProgram.
/// </Summary>
// Solution 2
Public static form FRM = NULL; // Save the variable of the new form after verification
Public static string username = ""; // Save the logon username and pass it to the new form.
[Stathread]
Static void main ()
{
Application. enablevisualstyles ();
Application. setcompatibletextrenderingdefault (false );
// Solution 1
// Note: after the verification is successful in the login form, execute:
// This. dialogresult = dialogresult. OK
// Login lg = New Login ();
// LG. showdialog ();
// If (lg. dialogresult = dialogresult. OK) application. Run (New form1 ());
// Solution 2
// Note: after the verification is successful in the login form, execute:
// Program. FRM = new form1 (); program. Username = logon username; this. Close ();
Application. Run (New login ());
If (FRM! = NULL) application. Run (FRM );
}
}
}