//关于GetCaretPos的定义,用来获取光标位置DllImport("user32")]
public static extern bool GetCaretPos(ref System.Drawing.Point lpPoint);
System.Drawing.Point CaretPos;
GetCaretPos(ref CaretPos);
//这下两行通不过啊,说受保护级别限制,刚开始学C#,找了半天MSDN不知所谓,哎~~
label1.Left=this.Left+CaretPos.x;
label1.Top=this.Top+CaretPos.y;

解决方案 »

  1.   

    private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
    System.Drawing.Point CaretPos;
    GetCaretPos(ref CaretPos);
    label1.Left=this.Left+CaretPos.x;
    label1.Top=this.Top+CaretPos.y;
    }
      

  2.   

    原来的代码是这个样子的,偶有点怀疑是那个private搞的鬼~~~:)不过人轻言微,有大虾现身指点才行private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
    System.Drawing.Point CaretPos;
    GetCaretPos(ref CaretPos);
    label1.Left=this.Left+CaretPos.x;
    label1.Top=this.Top+CaretPos.y;
    }
      

  3.   

    .x和.y改成大写就好了。。
    即CaretPos.X
      

  4.   

    .x和.y改成大写就好了。。
    即CaretPos.X
    ~~~~~~~~~~~~~~~~  说得有道理   如果是的话 那就是习惯问题了
    小写表示私有,大写表示公共