saptechnique

Better late than never. - 郭富

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
问题:
希望设置TextBox 中的光标到任意位置。

设置SelectStart 和Length 不一地起作用,并不希望选中文本。

解决方案:
使用一下代码就可以

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
 
        
public void SetCursorPosofTextBox(TextBox txb,int pos)
        
{
            txb.Focus();
            SendMessage(txb
.Handle,177,pos,pos);
        }


调用:

SetCursorPosofTextBox(this.textBox1,3);        
posted on 2010-03-07 23:50  guofu  阅读(522)  评论(0编辑  收藏  举报