forum

Home / DeveloperSection / Forums / Handling multiple button actions in one action in C#

Handling multiple button actions in one action in C#

Manoj Bhatt 2164 13-Nov-2013

I have 70 buttons whose names are like button1, button2, button3 and so on. My aim is that whenever button1 is clicked, it will say "1", button2 will say as "2" and so on for the others.

The code for button1 to speak is:

SpeechSynthesizer synthesizer = new SpeechSynthesizer();
private void button1_Click(object sender, EventArgs e)
{
    synthesizer.Speak("1");
}
For button2
private void button2_Click(object sender, EventArgs e)
{
    synthesizer.Speak("2");
}

and so on for other 68 buttons.

Now it is difficult to implement the 70 button's actions. These button actions follow a pattern - so can anyone suggest a more efficient way I can implement these button handlers to save me writing out 70 different actions?


c# c# 
Updated on 13-Nov-2013

Can you answer this question?


Answer

1 Answers

Liked By