hi,
I want to create number pad, so that it can be used for both simple calculator and keypad of a mobile phone where only keypress event works. I treid the code but I couldn't get for keypress event 3 times for the button . please help me..
Loading

Danatas GerviRank #4,152 · 361 reputationPosted Aug 26, 2009, 8:00 AM EDT
Here is example without modes (lets say - not calculator, extendet sms mode)
Before insert this code, place on form two buttons and one label.
namespace NumberPad
{
public partial class Form1 : Form
{
Button m_LastPressedButton;
int m_charIndex = 0;
public Form1()
{
InitializeComponent();
this.button1.Tag = (object)"2abc";
this.button2.Tag = (object)"3def";
this.button1.Click += new System.EventHandler(this.buttonS_Click);
this.button2.Click += new System.EventHandler(this.buttonS_Click);
}
private void buttonS_Click(object sender, EventArgs e)
{
Button pressedButton = sender as Button;
char buttonChar;
if (pressedButton.Equals(m_LastPressedButton))
{
string buttonChars = pressedButton.Tag.ToString();
buttonChar = buttonChars[m_charIndex++];
label1.Text += buttonChar;
if (m_charIndex >= buttonChars.Length)
{
m_charIndex = 0;
}
}
else
{
m_charIndex = 0;
m_LastPressedButton = pressedButton;
string buttonChars = pressedButton.Tag.ToString();
buttonChar = buttonChars[m_charIndex++];
label1.Text += buttonChar;
}
}
}
}
srinath133 reputationPosted Aug 27, 2009, 2:58 AM EDT
Danatas GerviRank #4,152 · 361 reputationPosted Aug 30, 2009, 1:58 AM EDT
I was trying to explain how to use one event handler to handle various buttons presses – by storing the data linked to button before using (in init stage). Next, you should decide how to use modes of keypad (only you know, which and how many) to take this data....