文本框专注于按键 [英] Textbox focus on keypress

查看:54
本文介绍了文本框专注于按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发计算器程序。就像Windows calcultor一样,它的文本框得到了集中并导致输入。在代码中,它不会专注于按键。

我需要手动点击文本框然后从键盘输入。



I am developing calculator program.As like windows calcultor on press its textbox get focused and cause to input. In code it dont get focused on key press.
I need manually click on textbox and then It take input from keyboard.

private void onKeyPress(object sender, KeyPressEventArgs e)
      {
          if (!char.IsControl(e.KeyChar) &&  char.IsDigit(e.KeyChar) &&(e.KeyChar != '.'))
          {
              e.Handled = true;
          }

          // only allow one decimal point
          if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
          {
              e.Handled = true;
          }
         txtResult.text = e.keyChar;
      }



仍然没有把重点放在按键上。


still it dont get focus on keypress.

推荐答案

please调用函数后跟onkeypress属性,类似这样:







或者交替:







函数myFunction()

{

textbox1.focus();

}
please call a function followed by onkeypress Attribute, Something like this:



or alternately:



function myFunction()
{
textbox1.focus();
}


如果您在网页中的计算器程序然后编写java脚本函数。



if your calculator program in a web page then write java script function.


document )。ready(< span class =code-keyword> function (){
textbox1.focus();
});
(document).ready(function () { textbox1.focus(); });







窗口应用此链接可能有用。



http: //stackoverflow.com/questions/6597196/how-to-put-focus-on-textbox-when-the-form-load [ ^ ]


这篇关于文本框专注于按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆