圖形控制項 (TGraphicControl 衍生) 無視窗控制代碼、不接收鍵盤焦點,但支援滑鼠/拖放互動,輕量高效。
unit Shapes;
interface
uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms;
type
TSampleShape = class(TGraphicControl)
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TSampleShape]);
end;
end.
RegisterComponents 將元件放入調色盤 Samples 頁。
TGraphicControl 已發布視覺屬性,需補充滑鼠/拖放互動:
type
TSampleShape = class(TGraphicControl)
published
property DragCursor;
property DragMode;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
獲得完整滑鼠回應與拖放能力。
兩大子任務:
Paint 虛擬方法實作繪圖邏輯。後續文章將逐步實作完整 TSampleShape 元件。