解決 Delphi 表單設置Constraints後 |
|
jackkcg
站務副站長 發表:891 回覆:1050 積分:848 註冊:2002-03-23 發送簡訊給我 |
此為囀貼資料 解決 Delphi 表單設置Constraints後
在左邊界或上邊界改變表單大小右邊界或下邊界跟著動的問題
Delphi 5 調試成功,應在 D4 D5 D6 中適用
沒脾氣
//////////////////////////////////////////////
type
TForm1 = class(TCustomForm)
//...
protected
procedure WMWindowPosChanging(var Msg: TWMWindowPosChanging);
message WM_WINDOWPOSCHANGING;
public
//...
end; procedure TForm1.WMWindowPosChanging(var Msg: TWMWindowPosChanging);
var
aRect: TRect;
begin
Windows.GetWindowRect( Msg.WindowPos.hwnd, aRect ); if (Msg.WindowPos.flags and SWP_NOSIZE = 0 ) then
begin
if Msg.WindowPos.cx < Self.Constraints.MinWidth then
begin
Msg.WindowPos.cx := Self.Constraints.MinWidth; if Msg.WindowPos.x <> aRect.Left then
begin
Msg.WindowPos.x := aRect.Right - Msg.WindowPos.cx;
end;
end else
if (Self.Constraints.MaxWidth > 0)
and(Msg.WindowPos.cx > Self.Constraints.MaxWidth) then
begin
Msg.WindowPos.cx := Self.Constraints.MaxWidth;
if Msg.WindowPos.x <> aRect.Left then
begin
Msg.WindowPos.x := aRect.Right - Msg.WindowPos.cx;
end;
end; if Msg.WindowPos.cy < Self.Constraints.MinHeight then
begin
Msg.WindowPos.cy := Self.Constraints.MinHeight; if Msg.WindowPos.y <> aRect.Top then
begin
Msg.WindowPos.y := aRect.Bottom - Msg.WindowPos.cy;
end;
end else
if (Self.Constraints.MaxHeight > 0)
and(Msg.WindowPos.cy > Self.Constraints.MaxHeight) then
begin
Msg.WindowPos.cy := Self.Constraints.MaxHeight;
if Msg.WindowPos.y <> aRect.Top then
begin
Msg.WindowPos.y := aRect.Bottom - Msg.WindowPos.cy;
end;
end;
end;
inherited;
end; // 沒脾氣,notemper@hoolee.com,zhaixudong@shareware.com.cn
// 2001.5.9 // 可能每次消息觸發都執行 GetWindowRect 會影響效率,若有更優解決辦法請告知。
//////////////////////////////////////////////
------
********************************************************** 哈哈&兵燹 最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好 Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知 K.表Knowlege 知識,就是本站的標語:Open our mind |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |