We are doing a login screen, click on the login button, we want it to close the form now and then jump to the form we need to sign in to, and we just want to have a form on the desktop instead of overlapping between a form. We do two types of bool in the Login interface class, which is used to sign the form to be landed, and to make two of them public. The main idea is: the landing form as a modal form, and then the landing of the form is set to the main form.
Login form:
Form one:
Form two:
when we click on the form one or the form two buttons in the login interface, we will log on to form one or form two and then close the login screen. But we have to revise the program and login procedures.
Program:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacetest{Static classProgram {/// <summary> ///The main entry point for the application. /// </summary>[STAThread]Static voidMain () {application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); Login Login=NewLogin ();//Create a login formLogin.showdialog ();//display mode login form if(Login.form1) {Application.Run (NewForm_one ());//take form one main form } Else if(Login.form2) {Application.Run (NewForm_two ());//take form two as the main form } } }}
Login:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacetest{ Public Partial classLogin:form {//a global variable for the class that controls the form's main form Public BOOLForm1 =false; Public BOOLForm2 =false; PublicLogin () {InitializeComponent (); } Private voidButton1_Click (Objectsender, EventArgs e) {Form1=true; This. Close ();//Close the form now } Private voidButton2_Click (Objectsender, EventArgs e) {Form2=true; This. Close ();//Close the form now } }}
C # Landing Form jump