使用下面的方法可以讓控件在運行狀態改變大小,就像在窗體編輯器中一樣.
type
tddhsizebutton=class(tbutton)
public
procedure WmNcHitTest(var msg:TWmNcHitTest);
message wm_NcHitTest;
end;
procedure TDdhSizeButton.WmNcHitTest(var msg:TWmNcHitTest);
var
pt:tpoint;
begin
pt:=point(msg.xpos,msg.ypos);
pt:=ScreentoClIEnt(pt);
if (pt.x<5) and (pt.y<5) then
msg.Result:=httopright
else if (pt.x>width-5) and (pt.y<5) then
msg.Result:=httopright
else if (pt.x >width-5) and (pt.y>height-5) then
msg.Result:=htbottomright
else if (pt.x<5) and (pt.y>height-5) then
msg.Result:=htbottomleft
else if (pt.x<5) then
msg.Result:=htleft
else if (pt.y<5) then
msg.Result:=httop
else if (pt.x>width-5) then
msg.Result:=htright
else if (pt.y>height-5) then
msg.Result:=htbottom
else
inherited;
end;