Delphi執行時拖拉、改變元件大小

應要求在程式執行時還要可以拉拖、改變元件大家~
分享一個不錯的函數
[pascal]
procedure DragResizeControl(WinControl: TControl; Shift: TShiftState;X, Y, Precision: integer);
var
SC_MANIPULATE: Word;
begin
if (X<=Precision) and (Y>Precision) and (Y<WinControl.Height-Precision) then begin
SC_MANIPULATE := $F001;
WinControl.Cursor := crSizeWE;
end else if (X>=WinControl.Width-Precision)
and (Y>Precision) and (Y<WinControl.Height-Precision) then begin
SC_MANIPULATE := $F002;
WinControl.Cursor := crSizeWE;
end else if (X>Precision)
and (X<WinControl.Width-Precision) and (Y<=Precision) then begin
SC_MANIPULATE := $F003;
WinControl.Cursor := crSizeNS;
end else if (X>Precision)
and (X<WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then begin
SC_MANIPULATE := $F006;
WinControl.Cursor := crSizeNS;
end else if (X<=Precision) and (Y<=Precision) then begin
SC_MANIPULATE := $F004;
WinControl.Cursor := crSizeNWSE;
end else if (X>=WinControl.Width-Precision) and (Y<=Precision) then begin
SC_MANIPULATE := $F005;
WinControl.Cursor := crSizeNESW ;
end else if (X<=Precision) and (Y>=WinControl.Height-Precision) then begin
SC_MANIPULATE := $F007;
WinControl.Cursor := crSizeNESW;
end else if (X>=WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then begin
SC_MANIPULATE := $F008;
WinControl.Cursor := crSizeNWSE;
end else if (X>5) and (Y>5) and (X<WinControl.Width-5)
and (Y<WinControl.Height-5) then begin
SC_MANIPULATE := $F009;
WinControl.Cursor := crSizeAll;
end else begin
SC_MANIPULATE := $F000;
WinControl.Cursor := crDefault;
end;

if Shift=[ssLeft] then begin
ReleaseCapture;
WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
end;
end;
[/pascal]
如用方法很簡單,在元件的MouseMove裡加上
[pascal]
DragResizeControl((Sender as TWinControl),Shift,X,Y,10);
[/pascal]

作者: 林壽山

目前任職於軟體公司研究開發部門,擔任專業處長,專注於.NET C# 開發,並具備豐富的POS 收銀系統與金流整合開發經驗。我精通各類支付系統的設計與開發,包含第三方支付(如綠界、藍新、歐付寶、速買配、馬來西亞 ePay/HappyPay、台新 One 碼)、行動支付(悠遊卡、一卡通、支付寶、微信支付、街口支付)、以及信用卡支付(聯合信用卡)。 熟悉多種開發技術,擅長PHP 網頁開發(CodeIgniter、Laravel 框架)、Delphi 程式設計、資料庫設計、C# WinForm/WebForm 應用開發、ASP.NET MVC、API 串接設計,並具備LINE 串接開發的豐富經驗。 除了技術開發之外,我也熱衷於技術分享,曾擔任台中學校產業學院講師 5 年,培育新一代的軟體開發人才,致力於推動軟體技術的應用與創新。 我對技術充滿熱忱,始終保持學習與探索的心態,期望透過軟體開發為企業與社會創造更大的價值。