Hello guys, im stuck working on a simulation program. I am working on a program which mimics a door's security key panel. In case if you have been wondering what a door's security key panel is.. its a keypad on the door which unlocks the door upon entering a proper password (in this case a combination of 0-9 and * & # symbols.
I've created a form and added 12 buttons on it. Whose Text reads 1,2,3,4,5,6,7,8,9,*,0,#. Also I have added a picture box whose default image is a black image. Now according to my simulation, all I need is to enter a 4 character password and if i enter the password right, the picture box's image would change (to green if correct or red if wrong password resp.)
I dont know how you professionals do it. But I have come up with an idea of mine to capture the sequence of key presses.
this is how I do it:
on click() event on every button, I assign a value of the button respective to the text of the button pressed.
for eg: lets assume button1 has its Text "1, and button2 has its Text "2"... so its event would be something like..
private value;
private void button1_click(object sender, EventArgs e)
{
value ="1";
}
private void button2_click(object sender, EventArgs e)
{
value ="2";
}
private void button3_click(object sender, EventArgs e)
{
value ="3";
}
and so on..
I made a custom function which saves the key presses in an ArrayList
private ArrayList myList = new ArrayList(3);
private void captureData(string content)
{
myList.Add(content);
}
now that this function adds data to an ArrayList, i need to feed data into this ArrayList. So I modify my button events to the following:
private value;
private void button1_click(object sender, EventArgs e)
{
value ="1";
if(myList.Capacity<=3)
{
captureData(value);
}
else
{
// do something else
}
}
private void button2_click(object sender, EventArgs e)
{
value ="2";
if(myList.Capacity<=3)
{
captureData(value);
}
else
{
// do something else
}
}
private void button3_click(object sender, EventArgs e)
{
value ="3";
if(myList.Capacity<=3)
{
captureData(value);
}
else
{
// do something else
}
}
and so on... so far so good..
now my problem starts here.
1. I have included a If construct on the buttons to check the number of characters the user pressed. I need it to limit it to 4. How do I do that? Ive tried changing array size and changed the <=3 to 2 and 4; it didnt help. MY LOGIC FAILS ME HERE.
2. ALSO im trying to include a compare function in else part of the button which invokes a function as soon as the user presses and releases the 4th part of the password. How do I do that?
any help here would be greatly appreciated..
Thanks for your time.
cheers!