确定在 TextBox 中按下 Enter 键

编程入门 行业动态 更新时间:2024-10-26 12:35:44
本文介绍了确定在 TextBox 中按下 Enter 键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

考虑在 Win Phone 7 中使用 XAML 文本框.

Consider a XAML TextBox in Win Phone 7.

  <TextBox x:Name="UserNumber"   />

这里的目标是当用户按下屏幕键盘上的 Enter 按钮时,这将启动一些逻辑来刷新屏幕上的内容.

The goal here is that when the user presses the Enter button on the on-screen keyboard, that would kick off some logic to refresh the content on the screen.

我想要专门为 Enter 引发一个事件.这可能吗?

I'd like to have an event raised specifically for Enter. Is this possible?

该事件是特定于 TextBox 的,还是系统键盘事件?是否需要检查每次按键时的 Enter 键?即类似于 ASCII 13?对此需求进行编码的最佳方式是什么? Is the event specific to the TextBox, or is it a system keyboard event? Does it require a check for the Enter on each keypress? i.e. some analog to ASCII 13? What's the best way to code this requirement?

推荐答案

在文本框中解决此问题的直接方法是

A straight forward approach for this in a textbox is

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
        Debug.WriteLine("Enter");
    }
}

这篇关于确定在 TextBox 中按下 Enter 键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 15:19:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1119302.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按下   TextBox   Enter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!