专注于csharp中的特殊文本框 [英] focus on special textbox in csharp

查看:107
本文介绍了专注于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屋!

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