5
I have events to which when pressing different keys performs some actions but I need to use the Esma thing in more than one form, how can I do this?
I found a little complicated the issue of inheritance in C# Windows Forms.
An example I use to capture the keystrokes and synthesize them.
I put an example of what I want to use in another form, but I put a snippet and as it is quite extensive it would look bad to copy and paste in other Forms. In the code below when pressing the keys I use the synthesizer to play them.
public void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.NumPad1)
{
sintetiza.SpeakAsync("1");
}
if (e.KeyCode == Keys.NumPad2)
{
sintetiza.SpeakAsync("2");
}
if (e.KeyCode == Keys.NumPad3)
{
sintetiza.SpeakAsync("3");
}
if (e.KeyCode == Keys.NumPad4)
{
sintetiza.SpeakAsync("4");
}
if (e.KeyCode == Keys.NumPad5)
{
sintetiza.SpeakAsync("5");
}
if (e.KeyCode == Keys.NumPad6)
{
sintetiza.SpeakAsync("6");
}
if (e.KeyCode == Keys.NumPad7)
{
sintetiza.SpeakAsync("7");
}
if (e.KeyCode == Keys.NumPad8)
{
sintetiza.SpeakAsync("8");
}
if (e.KeyCode == Keys.NumPad9)
{
sintetiza.SpeakAsync("9");
}
if (e.KeyCode == Keys.NumPad0)
{
sintetiza.SpeakAsync("0");
}
if (e.KeyCode == Keys.D1)
{
sintetiza.SpeakAsync("1");
}
if (e.KeyCode == Keys.D2)
{
sintetiza.SpeakAsync("2");
}
if (e.KeyCode == Keys.D3)
{
sintetiza.SpeakAsync("3");
}
if (e.KeyCode == Keys.D4)
{
sintetiza.SpeakAsync("4");
}
if (e.KeyCode == Keys.D5)
{
sintetiza.SpeakAsync("5");
}
if (e.KeyCode == Keys.D6)
{
sintetiza.SpeakAsync("6");
}
if (e.KeyCode == Keys.D7)
{
sintetiza.SpeakAsync("7");
}
if (e.KeyCode == Keys.D8)
{
sintetiza.SpeakAsync("8");
}
if (e.KeyCode == Keys.D9)
{
sintetiza.SpeakAsync("9");
}
if (e.KeyCode == Keys.D0)
{
sintetiza.SpeakAsync("0");
}}
What kind of code do you want to reuse? You can post an example?
– Jéf Bueno
Young man, what is
sintetiza
?– Jéf Bueno
synthesises is the object created, using the Speech API, to synthesize texts..
– LocalHost
Did any of the answers below solve your problem? Do you think you can accept one of them? Check out the [tour] how to do this, if you still don’t know how to do it. This helps the community by identifying the best solution for you. You can only accept one of them, but you can vote for any question or answer you find useful on the entire site.
– Maniero