[英]C#: How to make pressing enter in a text box trigger a button, yet still allow shortcuts such as “Ctrl+A” to get through?
[英]How to trigger button click event on pressing enter button in c#
我正在windows phone app中創建一個登錄表單,我想在完成表單時按下enter按鈕觸發登錄按鈕事件。
要求:在登錄頁面的上一個文本字段中單擊“輸入”按鈕時,應觸發登錄按鈕事件。
代碼示例我知道如何通過單擊輸入按鈕從一個文本字段移動到另一個文本字段,如下所示
private void passkeydown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
nextfield .Focus();
}
}
但我不知道如何觸發按鈕點擊事件。
試試這個:
if (e.Key == Key.Enter)
{
LoginButton_Click(sender,e); //here LoginButton_Click is click eventhandler
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.