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;
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;
如果只要取到Edit1容器的Left的话,就这样就可以了..: procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(IntToStr(Edit1.Panent.Left)); end;
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;这个好像是正解
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表示的坐标不是很准确?
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具有边框效果,取出来的值精确吗?....测试中.....
TEdit.Panent.Left就是窗体1的Left,在Panel1上,那就是Panel1的Left了....
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;
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;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(Edit1.Panent.Left));
end;
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;这个好像是正解
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表示的坐标不是很准确?
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具有边框效果,取出来的值精确吗?....测试中.....
--------
Windows.ScreenToClient(Form1.Handle,p);
改成
p:= Edit1.ScreenToClient(p);
OKP := Point(Edit1.left,Edit1.Top);Edit1 在Panel1上 P := Form1.ScreenToClient( Panel1.ClientToScreen(p));谢谢!