private void mylogin_Load(object sender, EventArgs e)
{
this.textBox1.Focus();
}也试过了
private void mylogin_Activated(object sender, EventArgs e)
{
this.textBox1.Focus();
}
都不行
请教大家原因,如何解决,谢谢
{
this.textBox1.Focus();
}也试过了
private void mylogin_Activated(object sender, EventArgs e)
{
this.textBox1.Focus();
}
都不行
请教大家原因,如何解决,谢谢
this.textBox1.SelectAll();试试??
private void Form1_Shown(object sender, EventArgs e)
{
if (this.textBox1.CanFocus)
this.textBox1.Focus();
}
推荐的是Select(),不带参数激活控件,带参数激活+选择
这是MSDN上讲的
2.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 WindowsFormsApplication19
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); this.Shown += new EventHandler(Form1_Shown);
} void Form1_Shown(object sender, EventArgs e)
{
textBox3.Focus();
}
}
}
其次,Form的Shown事件试试
private void mylogin_Load(object sender, EventArgs e)
{
this.textBox1.tabindex=0;
this.btn.tabindex=1;
this.textbox.focus()
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.Focus();
}
}
}
_______________________________________________________
你可能是TabIndex属性的值没有设对
可以用设置 textBox1的TabIndex属性
this.textBox1.Select();
成功