如何在C#中创建文本框Keydown事件 [英] How to create the Text box Keydown event in C#

查看:469
本文介绍了如何在C#中创建文本框Keydown事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请解释Windows应用程序中的Textbox Keydown事件.

例如,如果我单击Enter键,它将打开新的UI.

Please explain the Textbox Keydown event in windows application.

For example if i click the enter key it will open the new UI.

推荐答案

在基于Web的应用程序中? 您需要使用Javascript.用JavaScript编写函数,并在文本框的keypress事件上调用它.这是示例.

.aspx页面
In webbased application ?
You need to take help of Javascript. write a function in javascript and call it on keypress event of textbox. here is example.

.aspx page
<asp:textbox id="txtsubmit" runat="server" onkeypress="return callME()" xmlns:asp="#unknown" />



Javascript函数.



Javascript function.

function CalllME()
{
  if(event.keyCode == 13) //enter Keycode is 13
  {
     window.open(//Open new UI);
     return false;
  }

}


为TextBox的KeyDown事件添加处理程序. (这假定您将AcceptsReturn属性设置为False).然后在KeyDown事件处理程序中输入以下代码:

Add a handler for your TextBox''s KeyDown event. (This assumes you set the AcceptsReturn property to False). Then in your KeyDown eventhandler, have code such as:

if (e.KeyCode = Keys.Enter)
          window.open();//code to open your UI



另请参阅此链接:

http://www.dotnetperls.com/keycode [



Also refer this link:

http://www.dotnetperls.com/keycode[^]


有文本框Keydown事件.用于检查是否按下回车键.
There is event of Keydown for textbox. use to check if enter is pressed.
Private void txtbrowse_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles btnBrowse.KeyDown
{
     if (e.KeyData = Keys.Enter)
     {
          //open new UI
     }
}


这篇关于如何在C#中创建文本框Keydown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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