First create a new original form, as follows:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacewindowsformsapplication11{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidTssave_click (Objectsender, EventArgs e) { if(RDB02. Checked) {frmpwd F=Newfrmpwd (); F.formclosed+=NewFormclosedeventhandler (f_formclosed);//Event NotificationF.showdialog (); } Else{test (); } } voidTest () {MessageBox.Show ("Test"); } voidF_formclosed (Objectsender, Formclosedeventargs e) { if(Sender asFRMPWD). Ispass)//Ispass is the defined global variable in the form that receives the password input, and sender is the parameter that triggers the event.{test (); } Else{MessageBox.Show ("Password Error"); } } }}
Forms that the password receives:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacewindowsformsapplication11{ Public Partial classFrmpwd:form { Public BOOLIspass =false;//If the password is correct, the assignment is true and the default is False Publicfrmpwd () {InitializeComponent (); } Private voidButton1_Click (Objectsender, EventArgs e) { stringStrpwd = This. TextBox1.Text.Trim (); if(Strpwd = ="12345") {Ispass=true; } This. Hide (); This. Close (); } }}
The following conditions are required to verify the password:
You do not need to verify the password as follows, directly execute the corresponding function:
C # operation when receiving user input password to confirm