delphi 怎样获取窗体四个角的坐标

希望获取窗体四个角的坐标从而判断鼠标是否在窗体范围内移动
2025-12-15 06:13:37
推荐回答(1个)
回答1:

获取窗体[Form1]的四个角的坐标:

var
rect: TRect;
begin
GetWindowRect(Form1.Handle, rect);
ShowMessage('窗体左上角坐标:('+IntToStr(rect.Left) + ', ' + IntToStr(rect.Top)+')');
ShowMessage('窗体左下角坐标:('+IntToStr(rect.Left) + ', ' + IntToStr(rect.Bottom)+')');
ShowMessage('窗体右上角坐标:('+IntToStr(rect.Right) + ', ' + IntToStr(rect.Top)+')');
ShowMessage('窗体右下角坐标:('+IntToStr(rect.Right) + ', ' + IntToStr(rect.Bottom)+')');

end;