[英]Making Numpad in c# winforms not working
private void btnPress_Click(object sender, EventArgs e)
{
String key = ((Button)sender).Text;
InputSimulator.SimulateTextEntry(key);
SendKeys.SendWait(VirtualKeyCode.NUMPAD4.ToString());
}
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hWnd);
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new KeyPress());
}
请这东西没有任何帮助。 当我单击我的文本框并单击on button1时,那么1不会出现在这里..并且文本框焦点也丢失了。
好吧,如果我得到你,你需要一些类似的东西
private TextBox _lastFocused; defined in your form
然后将一个OnEnter或OnExit添加到每个参与的文本框设置_lastFocused,这样您就知道您希望按键进入哪个控件
然后在您的buttonClick(s)
String key = ((Button)sender).Text;
_lastFocused.Focus();
InputSimulator.SimulateTextEntry(key);
SendKeys.SendWait(VirtualKeyCode.NUMPAD4.ToString());
((Button)sender).Focus(); // if you want to out focus back the button clicked
据我所知,单击该按钮会将焦点从您所在的文本框移到该按钮上。 Sendkeys将模拟的按键路由到当前集中的控件,当然这是您的按钮。 因此,解决方法只是将焦点移回到上次来自的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.