TextBox.SelectionStart = index;
TextBox.SelectionLength = 0;
TextBox.SelectedText = "XXXXX";

解决方案 »

  1.   

    多谢!搞定了!!
    private void button1_Click(object sender, System.EventArgs e) {
          int start = this.textBox1.SelectionStart;    // 记录插入符的初始位置
          this.textBox1.SelectionLength = 0;           // 在插入符处
          this.textBox1.SelectedText = "for(;;) {}";   // 插入文本
          start += 4;                                  // 将插入符的位置向后移4位!!
          this.textBox1.SelectionStart = start;        // 重新设置插入符位置!!
          this.textBox1.Focus();                       // 设置焦点
    }
    试过以后没问题!