1. TextBox所属的窗体(Form)在可 *** 作(Active)状态. 即用户选中了Form.
2. TextBox的Enable属性,Visiable属性为True.
你在窗体加载时调用Focus()函数时, TextBox还未能成功的被显示到界面上.
所以导致了失败.
应修改为, 在Form的Activated事件中添加this.txtID.Focus(), 即可获得焦点.
我给你个示例.
using System
using System.Collections.Generic
using System.ComponentModel
using System.Data
using System.Drawing
using System.Linq
using System.Text
using System.Windows.Forms
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent()
}
private void Form1_Activated(object sender, EventArgs e)
{
textBox1.Focus()
}
}
}
希望对你有帮助.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)