private void mylogin_Load(object sender, EventArgs e)
        {
            this.textBox1.Focus();
        }也试过了
  private void mylogin_Activated(object sender, EventArgs e)
        {
            this.textBox1.Focus();
            
        }
都不行
请教大家原因,如何解决,谢谢

解决方案 »

  1.   

    this.textBox1.Focus(); 
    this.textBox1.SelectAll();试试??
      

  2.   


     private void Form1_Shown(object sender, EventArgs e)
            {
                if (this.textBox1.CanFocus)
                    this.textBox1.Focus();
            }
      

  3.   

    this.textBox1.Focus(); Foucus是微软不推荐使用的方式(以前的老版本函数)
    推荐的是Select(),不带参数激活控件,带参数激活+选择
    这是MSDN上讲的
      

  4.   

    1.设置tabindex
    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(); 
            }
        }
    }
      

  5.   

    推荐用TabIndex,
    其次,Form的Shown事件试试
      

  6.   

    严肃的告诉你,tabindex不行,web下可行
      

  7.   

    Activated应该也是可以的,可能你窗口显示后移动过焦点了,比如赋值,Activated->Shown
      

  8.   

    设置Textbox 的Tabindex的值为0, 一定要手工写代码,然后把你页面下的控件中Tabindex为0控件 的改一下,也在代码里写,绝对可行,
    private void mylogin_Load(object sender, EventArgs e) 
            { 
                this.textBox1.tabindex=0;
    this.btn.tabindex=1;
    this.textbox.focus()
            } 
      

  9.   

    TabIndex=0后在设置this .textbox.focus()
      

  10.   

    using System;
    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属性
      

  11.   

    非常感谢大家
    this.textBox1.Select();
    成功