询问者
button(按钮)单击向TextBox(编辑框)模拟按键。 SendKeys.Send("1").按钮会获取焦点。导致编辑框不能接收模拟按键。

问题
全部回复
-
Hi 可推,
这个很好解决,在SendKey.Send 前调用textbox的focus方法就行了,范例:
private void Button_Click(object sender, EventArgs e) { textbox.Focus();//文本框获取焦点 SendKeys.Send("1"); }
Regards,
Moonlight
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已建议为答案 Herro wongMicrosoft contingent staff, Moderator 2016年4月28日 3:15
- 已标记为答案 Herro wongMicrosoft contingent staff, Moderator 2016年5月5日 7:40
- 取消答案标记 可推 2016年5月16日 2:10
- 取消建议作为答案 可推 2016年5月16日 2:10
-
Hi 可推,
加个临时变量并调用文本框Leave事件将控件存入,范例:
Control currControl = null; //绑定Leave事件 textbox1.Leave += (obj, arg) => { currControl = obj as TextBox; }//或者直接写个方法给所有需要操作的文本框绑定 //textbox2.Leave += (obj, arg) => { currControl = obj as TextBox; } private void button1_Click(object sender, EventArgs e) { currControl.Focus(); SendKeys.Send(“1”); currControl = null;//清理变量 }
Regards,
Moonlight
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
- 已编辑 Moonlight ShengMicrosoft contingent staff 2016年5月19日 6:34
- 已建议为答案 Moonlight ShengMicrosoft contingent staff 2016年7月12日 2:12