将光标放在WPF/C#中的文本框上 [英] Cursor Focus on Textbox in WPF/C#

查看:82
本文介绍了将光标放在WPF/C#中的文本框上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建屏幕键盘.我正在使用routedcommands处理按钮单击.问题是,当我单击键盘面板上的按钮时,焦点将移至该按钮,而不是文本框.该要求指出,光标应始终出现在文本框中,以指示下一个字符将被插入的位置.有没有一种方法可以让我在单击按钮时保持对文本框的关注.

I am currently in the process of creating a Onscreen keyboard. I am handling the button click using routedcommands. The issue is that when i click on the button in keyboard panel the focus shifts to the button rather than on the Textbox. The requirement states that a cursor should always appear in the text box to indicate the position where the next character will be inserted. Is there a way i can keep focus on the textbox while button is clicked.

推荐答案

为输入控件设置逻辑焦点

To set logical focus to an input control

FocusManager.SetFocusedElement(this, textboxJack);     // set logical focus

要将键盘焦点设置为输入控件

To set keyboard focus to an input control

Keyboard.Focus(textboxJill);                             // set keyboard focus

要了解逻辑焦点和键盘焦点之间的区别

To know the difference between logical and keyboard focus

输入概述-专注于MSDN

这篇关于将光标放在WPF/C#中的文本框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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