Cursor Focus on Textbox in WPF/C#(光标聚焦在 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# 中的文本框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:光标聚焦在 WPF/C# 中的文本框上
基础教程推荐
- 从 C# 控制相机设备 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 如果条件可以为空 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
