I have three buttons (button1, button2, button3), displaying respectively 1, 2 and 3 on them
Now what I want to do is having a secret combination to ‘unlock’ the program, i.e. ‘13221’
But I have no clue on how I can know if a user has pressed a button, and how I can check the order?
My current logic is:
private void Form1_Load(object sender, EventArgs e)
{
if(button1.KeyPress=true && button3.KeyPress=true && button2.KeyPress=true && button2.KeyPress=true && button1.KeyPress=true)
{
label1.Visible = true;
label2.Visible = true;
}
}
Which doesn’t work obviously..
Anyone can help me out? :/
Use a StringBuilder object to store each keyed value into. So in each button’s click event, you will Append the ‘1’, ‘2’, or ‘3’ depending on which button is pressed, and then check the current sequence.