Home > Net >  How to set the permissions for the button and enter the correct password can freely within ten minut
How to set the permissions for the button and enter the correct password can freely within ten minut

Time:11-14

Fellow teachers, ask a question,
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 code
 public 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 Action Password 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 form
 bool 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 time

CodePudding user response:

refer to fifth floor a salted fish want to roll over response:
I set is 10 s, you modify the sleep time

Hello, can help annotate the meaning of each line of code? Don't understand,,,

CodePudding user response:

refer to 6th floor snail learn programming reply:
Quote: refer to the 5 floor a salted fish want to roll over response:
I set is 10 s, you modify the sleep time

Hello, can help annotate the meaning of each line of code? Don't understand,,,

, the alternative is to use a delegate one thread, written code is more casual (# -. -)

CodePudding user response:

System. The Threading. Timer forehead as if it's like this

CodePudding user response:

If we can only achieve without the timer function can realize
First click on the record the current time
After click compare record time to determine whether a time gap is more than 10 minutes
Two time variables directly subtraction can get TimeSpan variables of type
Have time gap of information in the TimeSpan

CodePudding user response:

You cross form controls the operation, must entrust,

CodePudding user response:

I am here to learn

CodePudding user response:

The easiest way to use DialogResult property
Main form
 
Private void button1_Click (object sender, EventArgs e)
{

Form2 FRM=new Form2 ();
FDialogResult Dr=FRM. ShowDialog ();
If (Dr==DialogResult. OK)
{
All functions can use
Can it be used for.=false;
Sleep (10 * 1000); Set the sleep time
Can it be used for.=true;
}
The else
{
All functions, not with
Can it be used for.=true;
}
}



Enter the password form
 
nullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related