textBox1.SelectionStart也不知道对不对,刚学C#,这是在C#回答的第一个问题!

解决方案 »

  1.   

    用javascript来实现,代码如下:
    <html>
    <head>
    <title>New Page 1</title>
    <script language="javascript">
    function CheckCur(Item)
    {
       var Text = Item.value;
       
       var currentRange=document.selection.createRange();
       
       document.all("B1").value = Text.length;
       document.all("B2").value = getCursorPos(Item);
    }function getCursorPos(obj) 
    {
     obj.focus();
     var currentRange=document.selection.createRange();
     var workRange=currentRange.duplicate();
     obj.select();
     var allRange=document.selection.createRange();
     var pos=0;
     while(workRange.compareEndPoints("StartToStart",allRange)>0)
     {
      workRange.moveStart("character",-1);
      pos++;
     }
     currentRange.select();
     return pos;
    }</script>
    </head><body><form method="POST" action="--WEBBOT-SELF--">
      <p><input type="text" name="T1" onkeyup="javascript:CheckCur(this)" size="20">
      <input type="button" value="aaa" name="B1">
      <input type="button" value="bbb" name="B2"></p>
    </form></body></html>
      

  2.   

    Sorry,没看仔细,我还以为在WebForm中呢,在WinForm中如一楼的做法即可:
    textBox1.SelectionStart.ToString();