怎么保持光标在textbox中始终选取一个字符!
大概如图
即鼠标在textbox中点任意位置是选取一个字符而不是一个光标位置
键盘输入时在当前选取的位置输入并移动光标到下一个位置并保持选取
不知道描述清楚了没有啊,我现在用如下方法实现了,但是很笨拙,那位能给出更好的办法啊!!
private void txt编号_KeyUp(object sender, KeyEventArgs e)
        {
            txt编号.SelectionStart = int.Parse(this.txt编号.SelectionStart.ToString());
            txt编号.SelectionLength = 1;
        }        private void txt编号_MouseDown(object sender, MouseEventArgs e)
        {
            txt编号.SelectionStart = int.Parse(this.txt编号.SelectionStart.ToString());
            txt编号.SelectionLength = 1;
        }textboxwinformc#

解决方案 »

  1.   

    能实现就行,管它本不笨拙
    有两行代码可以删除
    private void txt编号_KeyUp(object sender, KeyEventArgs e)
            {
                //txt编号.SelectionStart = int.Parse(this.txt编号.SelectionStart.ToString());
                txt编号.SelectionLength = 1;
            }        private void txt编号_MouseDown(object sender, MouseEventArgs e)
            {
                //txt编号.SelectionStart = int.Parse(this.txt编号.SelectionStart.ToString());
                txt编号.SelectionLength = 1;
            }
      

  2.   

    移动的话很简单
            private void txt编号_KeyDown(object sender, KeyEventArgs e)
            {
                    txt编号.SelectionStart = txt编号.Text.Length+1;
            }
      

  3.   

            private void textBox1_KeyUp(object sender, KeyEventArgs e)
            {
                if (textBox1.SelectionStart > 0)
                    textBox1.SelectionStart = textBox1.SelectionStart - 1;
                textBox1.SelectionLength = 1;
            }        private void textBox1_MouseDown(object sender, MouseEventArgs e)
            {
                textBox1.SelectionLength = 1;
            }
    虽然你的需求感觉挺怪,但上面这样应该能实现