If you show the numpad buttons in the same form
I've answered a similar questions here: How to create a Button that can send keys to a control without stealing the focus - Virtual Keyboard
You need to makes the buttons non-selectable, then clicking on it will not steal the focus:
public class ExButton:Button
{
public ExButton()
{
SetStyle(ControlStyles.Selectable, false);
}
}
Then handle click event and send key:
private void exButton1_Click(object sender, EventArgs e)
{
SendKeys.SendWait("A");
}
You can just easily replace all your button controls with MyButton (in the designer.cs), or at design time. But if for any reason you do not want to replace the buttons, you can rely on the following extension method:
public static class Extensions
{
public static void SetStyle(this Control control, ControlStyles flags, bool value)
{
Type type = control.GetType();
BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;
MethodInfo method = type.GetMethod("SetStyle", bindingFlags);
if (method != null)
{
object[] param = { flags, value };
method.Invoke(control, param);
}
}
}
And use it like this:
this.button1.SetStyle(ControlStyles.Selectable, false);