Now I want to implement a function: to prevent wrong click, need to provide a button to set the permissions (button2), click on the pop up after the password box, enter the correct password can unlock, after ten minutes, this button is normal operation, after ten minutes, the button lock again, must enter the password again to operate,
I design a form as the password box, but met the question is:
Still for an operation command after the operation, button2, according to gray,
In addition, how to let the button2 to false again after ten minutes? The introduction of the timer? How to write the code?
Teachers, please advise ~ ~
If (textBox1. Text=="123")//password
{
Form4 ff=new Form4 ();//let the main form of effective button2 can
Ff. Button2. Enabled=true;
Enclosing the Close ();
}
The else
{
MessageBox. Show (" wrong password, please enter again ");
}
CodePudding user response:
Design a system to interface with the interface behind the bound state (data source) separate design, makes "can change at different interface skin layer", this is can do large system design patterns, for example, can be designed so that the VM codepublic class status: INotifyPropertyChanged
{
Public bool is available
{
The get
{
Return a DateTime. Now & lt; Finally the unlock time. AddMinutes (1);
}
}
String _pwd;
Public string password
{
The get
{
Return _pwd;
}
Set
{
_pwd=value;
PropertyChanged? Invoke (this, new PropertyChangedEventArgs (" password "));
}
}
Public async Task to enter the password to unlock (string input)
{
If (input==password)
{
Finally the unlock time=DateTime. Now;
PropertyChanged? Invoke (this, new PropertyChangedEventArgs (" availability "));
Await Task. Delay (1000);
PropertyChanged? Invoke (this, new PropertyChangedEventArgs (" availability "));
}
The else
Password mistake? Invoke (input);
}
Private DateTime finally unlock time=DateTime. Now;
The public event PropertyChangedEventHandler PropertyChanged;
The public event ActionPassword error;
}
Here, the VM status data (data sources) there is a read-only property "availability" whether to show the current in the input password after 1 minute time period, and when this property from "unavailable" and "available" when switching between will trigger the PropertyChanged event notification host, as well as a "password" attribute is used to store, binding, event notification is used to check the password, there is also a "enter the password to unlock the asynchronous operation method, client calls it can change the state of" available ",
Design program, to separate the View and ViewModel design, for example, WPF, Knockout, Vue etc framework has a set of general mechanism can be "common data objects, data collection objects" and the View on the two-way binding properties of various existing control is very convenient, so the key is that programmers have consciousness, understand don't understand the design concept,
A good programmer, it can be used more than 2 or 3 kinds of UI, UE design to test the ViewModel state data object design, state of the same object can be adapted protean interface template, without changing the business logic code, only with "instead of" the common man is engineer, instead of bleeding, and only a few people can be successful,
CodePudding user response:
Await Task. Delay (60000);In terms of designing and writing the UI code, now of the.net framework far from web front-end interface components related framework is more close to actual combat, rather backward and trouble, such as ordinary object encapsulation as ViewModel object can completely by the Jit compiler savings, it embodies the Microsoft in the past 15 years without a real UI application development oriented system architects and only a bunch of small artisans, will only copy open source events purpose design thinking of embarrassment, but thin dead camel is bigger than the horse, Microsoft only still a little bit of cargo, or of some recent six or seven years. The net have to learn to master the new knowledge,
CodePudding user response:
Password box trigger buttons enable button the timer can make and change the password Settings, timer trigger button closure and restore the password Settings, carefully chosen three control triggering events, and then write the code to just go,CodePudding user response:
Main formbool flag=false;
Private void button1_Click (object sender, EventArgs e)
{
if (! Flag)
{
Form2 FRM=new Form2 ();
FRM. CheckStatus +=Frm_checkStatus;
FRM. The Show ();
}
}
Private void Frm_checkStatus (bool cflag)
{
Flag=cflag;
Thread=new thread (changeFlag);
Thread. The Start ();
}
Thread the Thread=null;
Private void changeFlag ()
{
While (flag)
{
Thread.sleep (10 * 1000);
flag=false;
}
}
The password input box
public delegate void Checkpassword (bool flag);
The public event Checkpassword checkStatus;
Private void button1_Click (object sender, EventArgs e)
{
If (textBox1. Text=="123456")
{
CheckStatus (true);
}
The else
{
CheckStatus (false);
}
Enclosing the Close ();
}
CodePudding user response:
I set is 10 s, you modify the sleep timeCodePudding user response: