很容易获得 TEdit 控件的外部尺寸,但其中包括斜角(或框架,取决于 Ctrl3d 是否为真)。我想找出TEdit的白色输入区域的尺寸和位置。
我尝试了 TEdit.ClientRect,但如果 Ctrl3D 为 true,它似乎只给出正确的大小。我仍然需要向左侧和顶部添加两个像素来调整斜角。
如果 Ctrl3D 为 false,则尺寸太大了两个像素,左/上偏移量必须增加一。
有没有办法获得该区域的正确大小和位置,例如使用 Windows API 函数?
最佳答案
在 Vista 及更高版本上,您可以使用 EM_GETRECT
消息:
function GetEditRect(Edit: TCustomEdit): TRect;
begin
SendMessage(Edit.Handle, EM_GETRECT, 0, LPARAM(@Result));
end;
不幸的是:
Under certain conditions,
EM_GETRECT
might not return the exact values thatEM_SETRECT
orEM_SETRECTNP
set—it will be approximately correct, but it can be off by a few pixels.
关于delphi - 如何确定 TEdit 的输入区域大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31566689/