The main idea is to minimize the number of tasks in the system tray area. Then, the mode dialog box is used to verify that the password entered by the user is correct. If the password is correct, the main form is displayed. Otherwise, ignore it. I mainly use the mode dialog box. The Return Value of the validation mode dialog box is worth noting. If the user enters the correct password, the value returned by the verification form is dialogresult. OK. Otherwise, dialogresult. Cancel is returned.
Main form: Main
Control: yyicon (notifyicon, Tray display)
Verification Form: Activate
Control: activate_txtb (Textbox, enter password), btn_ OK (button, OK), btn_cancel (button, cancel)
1. Click the Minimize button on the main form and place the task to the system tray.
Private void main_sizechanged (Object sender, eventargs E)
{
If (this. windowstate = formwindowstate. Minimized)
{
This. windowstate = formwindowstate. normal;
Policyicon. Visible = true;
This. Hide ();
This. showintaskbar = false;
}
}
2. Click the task icon in the system tray area to activate the verification form and perform corresponding operations based on the verification results.
Private void policyicon_click (Object sender, eventargs E)
{
Activate frmactivate = new activate ();
If (frmactivate. showdialog (this) = dialogresult. OK)
{
This. showintaskbar = true;
This. Show ();
This. Activate ();
Policyicon. Visible = false;
This. windowstate = formwindowstate. maximized;
}
Frmactivate. Dispose ();
}
3. The verification form returns the verification result, that is, the btn_ OK event.
Private void btn_ OK _click (Object sender, eventargs E)
{
// Obtain the verification password stored in the database, which is encrypted with MD5.
String tmp_pass = mydata. getfieldvalue ("sysinfo", "Activate ","");
// Obtain the password entered by the user and use MD5 Encryption
String tmp_input = myclass. returnmd5 (this. activate_txtb.text.tostring (). Trim ());
If (tmp_input = tmp_pass)
{
This. dialogresult = dialogresult. OK;
}
Else
{
This. dialogresult = dialogresult. Cancel;
}
}
Here is the advertisement