简单问题:取一个控件如(TEdit)相对与TForm的left , Top 属性

coreblood 2006-06-02 04:40:24
如提:简单问题:取一个控件如(TEdit)相对与TForm的left , Top 属性
控件可能在TPanl,TGroupBox等容器控件中,需考虑容器控件嵌套的问题。

谢谢了,希望大家踊跃发言.
...全文
188 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
coreblood 2006-06-03
  • 打赏
  • 举报
回复
p := TargetControl.ScreenToClient( SourceControl.ClientToScreen(p));
OK

P := Point(Edit1.left,Edit1.Top);

Edit1 在Panel1上

P := Form1.ScreenToClient( Panel1.ClientToScreen(p));

谢谢!
coreblood 2006-06-03
  • 打赏
  • 举报
回复
....继续测试看看....
老之 2006-06-03
  • 打赏
  • 举报
回复
怎么P表示的坐标不是很准确?
--------
Windows.ScreenToClient(Form1.Handle,p);
改成
p:= Edit1.ScreenToClient(p);
coreblood 2006-06-03
  • 打赏
  • 举报
回复
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具有边框效果,取出来的值精确吗?....

测试中.....
coreblood 2006-06-03
  • 打赏
  • 举报
回复
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表示的坐标不是很准确?
coreblood 2006-06-02
  • 打赏
  • 举报
回复
谢谢,大家响应...明天测试一下啊,我一向揭贴迅速.....
yyjzsl 2006-06-02
  • 打赏
  • 举报
回复
路过,顶下
happyggy 2006-06-02
  • 打赏
  • 举报
回复
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;

这个好像是正解
wudi_1982 2006-06-02
  • 打赏
  • 举报
回复
顶老之一个。。
GARNETT2183 2006-06-02
  • 打赏
  • 举报
回复
如果只要取到Edit1容器的Left的话,就这样就可以了..:


procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(Edit1.Panent.Left));
end;
老之 2006-06-02
  • 打赏
  • 举报
回复
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;
xixuemao 2006-06-02
  • 打赏
  • 举报
回复
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;
GARNETT2183 2006-06-02
  • 打赏
  • 举报
回复
比如TEdit在窗体1上,那
TEdit.Panent.Left就是窗体1的Left,在Panel1上,那就是Panel1的Left了....
terence4444 2006-06-02
  • 打赏
  • 举报
回复
应该可以通过相加的方式解决的吧,刚才试了一下 panel 是可行的(edit1.top+panel.top)
luxuewei5214 2006-06-02
  • 打赏
  • 举报
回复
递归,本控件的值加上父控件的值,直到父控件是TForm类型的

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧