例如当前光标在第五行,第三列,我想知道它在Richedit中的象素坐标?(例如210,101)

解决方案 »

  1.   

    可以直接用GetCaretPos得到坐标
      

  2.   

    我要的是在Richedit控件本身中的坐标,GetCaretPos得到的好像不是吧?
      

  3.   

    The caret position is always given in the client coordinates of the window that contains the caret.
    你完全可以自己试试
      

  4.   

    我参照下面的程序已解决给你个例子,不过我是用TMemo+TListBox实现的
    var t:TEXTMETRIC;MemoHdc:HDC;
    begin
      MemoHDC:=GetDC(Memo1.Handle);//得到Memo1的设备上下文句柄
      {得到Memo1的字体信息}
      GetTextMetrics(MemoHDC,t);
      //计算新坐标.+10和+20是为了防止把当前的Caret遮住了
      ListBox1.Left :=Memo1.Left+Memo1.CaretPos.X *t.tmAveCharWidth +10;
      ListBox1.top:=Memo1.Top+Memo1.CaretPos.Y *t.tmHeight +20 ;
      ReleaseDC(MemoHDC,Memo1.Handle );//用完了要释放调
    end;我的程序(其中r,c是当前的行列)        try
              RichEditHdc:=GetDC(RichEdit1.Handle);//
              GetTextMetrics(RichEditHdc,METRIC);
            except
              ReleaseDC(RichEditHdc,RichEdit1.Handle );
            end;
            lb_Code.Left:=METRIC.tmAveCharWidth*(C+1);
            lb_Code.Top :=METRIC.tmHeight*(R+1);