当前位置:编程学习 > C#/ASP.NET >>

急求光标定位代码

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


            this.textBox1.LostFocus += new EventHandler(textBox1_LostFocus);
        }

        void textBox1_LostFocus(object sender, EventArgs e)
        {
            //判断..
            bool flag = true;
            if (flag)
            {
                this.textBox1.Focus();
            }
        }
--------------------编程问答-------------------- 先判断是否符合条件,然后
textbox.focus(); --------------------编程问答-------------------- textbox.focus();
textbox..SelectAll(); --------------------编程问答-------------------- 2楼正解 --------------------编程问答-------------------- 妈呀,这个问题太简单了点吧? --------------------编程问答-------------------- 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());
}
--------------------编程问答--------------------
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,