I have events that when pressing different keys perform some actions but I need to use this thing in more than one form , how can I do this?
I found the issue of inheritance in C # Windows Forms a little complicated.
An example that I use to capture the keystroke and synthesize it.
I put an example of what I want to use in another form, but I put a snippet and as it is very extensive it would be bad to copy and paste into 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");
}}