如何从 WinForms 中的 TextBox 中移除焦点? [英] How to remove the focus from a TextBox in WinForms?

查看:17
本文介绍了如何从 WinForms 中的 TextBox 中移除焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从几个 TextBox 中移除焦点.我尝试使用:

I need to remove the focus from several TextBoxes. I tried using:

textBox1.Focused = false;

它的ReadOnly属性值为true.

然后我尝试将焦点设置在表单上,​​以便将其从所有 TextBoxes 中删除,但这也不起作用:

I then tried setting the focus on the form, so as to remove it from all the TextBoxes, but this also fails to work:

this.Focus();

当一个文本框被选中时,函数返回false.

and the function returns false when a textbox is selected.

那么,如何从 TextBox 中移除焦点?

So, how do I remove the focus from a TextBox?

推荐答案

您需要一些其他可聚焦的控件来将焦点移动到.

You need some other focusable control to move the focus to.

请注意,您可以将焦点设置为标签.您可能需要考虑下一步要将 [Tab] 键放在哪里.

Note that you can set the Focus to a Label. You might want to consider where you want the [Tab] key to take it next.

另请注意,您不能将其设置为表单.像 Form 和 Panel 这样的容器控件会将焦点传递给它们的第一个子控件.这可能是您希望它远离的 TextBox.

Also note that you cannot set it to the Form. Container controls like Form and Panel will pass the Focus on to their first child control. Which could be the TextBox you wanted it to move away from.

这篇关于如何从 WinForms 中的 TextBox 中移除焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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