如提:简单问题:取一个控件如(TEdit)相对与TForm的left , Top 属性
      控件可能在TPanl,TGroupBox等容器控件中,需考虑容器控件嵌套的问题。谢谢了,希望大家踊跃发言.

解决方案 »

  1.   

    递归,本控件的值加上父控件的值,直到父控件是TForm类型的
      

  2.   

    应该可以通过相加的方式解决的吧,刚才试了一下 panel 是可行的(edit1.top+panel.top)
      

  3.   

    比如TEdit在窗体1上,那
    TEdit.Panent.Left就是窗体1的Left,在Panel1上,那就是Panel1的Left了....
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      l,t: integer;
      c: TWinControl;
    begin
      l:= 0;
      t:= 0;
      c:= edit1;
      while c.Handle <> self.Handle do
      begin
        l:= l+c.Left;
        t:= t+c.Top;
        c:= c.Parent;
      end;
      edit1.Text:= inttostr(l)+'---'+inttostr(t);
    end;
      

  5.   

    var p:TPoint;
    begin
      p:=Point(Edit1.Left,Edit1.Top);
      Windows.ClientToScreen(Edit1.Handle,p);
      Windows.ScreenToClient(Form1.Handle,p);
      ShowMessage(Format('%d  %d',[P.X,P.Y]));
    end;
      

  6.   

    如果只要取到Edit1容器的Left的话,就这样就可以了..:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage(IntToStr(Edit1.Panent.Left));
    end;
      

  7.   

    var p:TPoint;
    begin
      p:=Point(Edit1.Left,Edit1.Top);
      Windows.ClientToScreen(Edit1.Handle,p);
      Windows.ScreenToClient(Form1.Handle,p);
      ShowMessage(Format('%d  %d',[P.X,P.Y]));
    end;这个好像是正解
      

  8.   

    var p:TPoint;
    begin
      p:=Point(Edit1.Left,Edit1.Top);
      Windows.ClientToScreen(Edit1.Handle,p);
      Windows.ScreenToClient(Form1.Handle,p);
      ShowMessage(Format('%d  %d',[P.X,P.Y]));
    end怎么P表示的坐标不是很准确?
      

  9.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      l,t: integer;
      c: TWinControl;
    begin
      l:= 0;
      t:= 0;
      c:= edit1;
      while c.Handle <> self.Handle do
      begin
        l:= l+c.Left;
        t:= t+c.Top;
        c:= c.Parent;
      end;
      edit1.Text:= inttostr(l)+'---'+inttostr(t);
    end;如果TPanl具有边框效果,取出来的值精确吗?....测试中.....
      

  10.   

    怎么P表示的坐标不是很准确?
    --------
    Windows.ScreenToClient(Form1.Handle,p);
    改成
    p:= Edit1.ScreenToClient(p);
      

  11.   

    p := TargetControl.ScreenToClient( SourceControl.ClientToScreen(p));
    OKP := Point(Edit1.left,Edit1.Top);Edit1 在Panel1上 P := Form1.ScreenToClient( Panel1.ClientToScreen(p));谢谢!