textbox 插入



我们经常使用textbox作为文字录入界面,下面时实现该功能代码

插入:(光标处插入)

                   string s = txtCode.Text;
                   idx = txtCode.SelectionStart;
                   s=s.Insert(idx, "T")

                   txtCode.Text = s;
                   txtCode.SelectionStart = idx+1;
                   txtCode.Focus();

回退:(光标处退格)

                       string s=txtCode.Text;
                       idx = txtCode.SelectionStart;
                       if (idx > 0)
                       {
                           txtCode.Text = s.Substring(0, idx - 1) + s.Substring(idx);
                           txtCode.SelectionStart = idx - 1;
                       }
                       else
                       {
                           txtCode.SelectionStart = 0;



Net 学习