After winform is minimized to the system tray, the implementation method to be verified is activated again.

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.