如何在textbox获取焦点的同时光标处在textbox里文字的最后一个文字的后面(如果textbox里有文字的话)?谢谢。

解决方案 »

  1.   

    textBox.Focus();
    textBox.Select(textBox.Text.Length(), 0);
      

  2.   


    <script language="javascript" type="text/javascript">
        function setCursorPos(x){  
            var txtRange = x.createTextRange(); 
            txtRange.moveStart("character", x.value.length); 
            txtRange.moveEnd("character", 0); 
            txtRange.select(); 
        }    <input type="text" value="1111" onfocus="setCursorPos(this)" />
        <input type="text" value="1111" onfocus="setCursorPos(this)" />
        <input type="text" value="1111" onfocus="setCursorPos(this)" />
      

  3.   

    textBox1.Focus(); 
                textBox1.SelectionStart = 1;/////"1"代表光标在第1个字符之后 
     具体请根据文本框里字符的长度设置吧
      

  4.   


    你用的VS什么版本的还有length后面没有括号 手误了
      

  5.   


    我的08就有这个方法
    你看看咱们的引用是一样的么
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
      

  6.   

    看这篇文章:http://www.webdeveloper.com/forum/showthread.php?t=74982
      

  7.   

    asp.net中的textbox获得焦点光标会默认的显示在最后一个字符的后面呀
      

  8.   

    <html>
    <head> 
    <title></title>
    <script>
            function   setfocus(txt_value)
            {
                var   obj= txt_value.createTextRange();
                obj.moveStart("character",txt_value.value.length);
                obj.moveEnd("character",0);
                obj.select();
            }    </script>
    </head>
    <body>
     <input name="TextBox1" type="text" value="123" id="TextBox1" onclick="setfocus(this)" />
    </body>
    </html>