专注于csharp中的特殊文本框 [英] focus on special textbox in csharp
问题描述
如何专注于特殊文本框?
how to focus on special textbox?
推荐答案
实际上,有三种方法可以设置焦点.第一种方法是使用表单的ActiveControl
属性.
There are, effectively, three ways that you can set the focus. The first way is to use the ActiveControl
property of your form.,
this.ActiveControl = txtSpecial;
方法是使用Select
方法,即
txtSpecial.Select();
第三种方法是使用Focus
方法.此方法假定该表单的ControlStyles.Selectable
位设置为true,并且您要关注的控件的父控件均未禁用.
The third method is to use the Focus
method. This method assumes that the ControlStyles.Selectable
bit is set to true for the form, and none of the parent controls of the control you are trying to focus on are disabled.
txtSpecial.Focus();
在所有情况下,您都需要等待Loaded
事件,然后才能尝试设置焦点.
In all cases, you need to wait for the Loaded
event before you can attempt to set the focus.
在显示形式"事件中设置焦点
Set the focus in the Form Shown event
这将是您将重点放在Winform上的方式:
This would be how you would set focus on Winform:
public myForm()
{
// Autogenerated.
InitializeComponent();
// Get focus on text box 1.
textBox1.Focus();
}
在 http://上进行了讨论. www.eggheadcafe.com/community/csharp/2/10074071/set-focus-on-text-box-when-loading-winform.aspx [
This is discussed at http://www.eggheadcafe.com/community/csharp/2/10074071/set-focus-on-text-box-when-loading-winform.aspx[^]
这篇关于专注于csharp中的特殊文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!