当用户输入的数据部符合要求的时候,比如输入的数据长度不够或者不输入,因为他是主键,必须输入正确,如果输入不正确,就将光标始终定位在那个文本框中textbox里面。

解决方案 »

  1.   

                this.textBox1.LostFocus += new EventHandler(textBox1_LostFocus);
            }        void textBox1_LostFocus(object sender, EventArgs e)
            {
                //判断..
                bool flag = true;
                if (flag)
                {
                    this.textBox1.Focus();
                }
            }
      

  2.   

    先判断是否符合条件,然后
    textbox.focus();
      

  3.   

    textbox.focus();
    textbox..SelectAll();
      

  4.   

    private void button1_Click(object sender, EventArgs e)
    {
        textBox1.SelectionStart = 2;
        textBox1.Focus();
    }// 取得光标位置
    private void button2_Click(object sender, EventArgs e)
    {
        MessageBox.Show(textBox1.SelectionStart.ToString());
    }